0

A csv file was exported from PostgreSQL database, but the exported file could not be imported into SQL Server, but same csv was easily imported into PostgreSQL.

Query to export was:

copy(select * from tablename where columnname = 'z') to '/path'
1
  • That does not produce a csv file. It is producing what PostgreSQL calls a text formatted file. Commented Aug 27, 2020 at 15:36

1 Answer 1

2

As mentioned in the comments, that statement does not create a CSV file. The correct syntax is:

copy(select * from tablename where columnname = 'z') to '/path/file_name.csv' delimiter ',' csv header;

A brief description of the options is below. See the documentation for more details.

  • DELIMITER - indicates the character separator to use. Default is tab for CSV
  • CSV - indicates CSV format
  • HEADER - the file should contain the header line with the column names
Sign up to request clarification or add additional context in comments.

Comments

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.