2

Is there any way to take a csv file with numerous values and feed these values into a postgres select statement. For example if i had a csv file called text.csv with values 1,2,3,4,5,6... is there a way for me to perform a select such as:

select * 
from table 
where id in (test.csv);

2 Answers 2

2

There is a fdw-file - https://www.postgresql.org/docs/current/static/file-fdw.html - foreign data wrapper which allows you to use file as table.

Here is example - http://www.postgresonline.com/journal/archives/250-File-FDW-Family-Part-1-file_fdw.html

Sign up to request clarification or add additional context in comments.

1 Comment

See in example - (after you create "foreign server" etc. as described) you will create so called "foreign table" and this table will behave as normal table in select. But data will be taken from file.
-1

Well this is how it can be done !

Select * from table where id in (
  select id from openrowset('MSDASQL'
               ,'Driver={Microsoft Text Driver (*.txt; *.csv)}'
               ,'select * from c:\test.csv')
  )

In case if your sql server is not enabled for Ad Hoc Distributed Queries, fire below sql first.

sp_configure 'show advanced options', 1;  
RECONFIGURE;
GO 
sp_configure 'Ad Hoc Distributed Queries', 1;  
RECONFIGURE;  
GO

Good Luck ! Keyur

1 Comment

That is invalid SQL and invalid for Postgres as well (the only two tags on the question)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.