简体   繁体   中英

Postgres query result into CSV in terminal wrongly quotes text values

I am using following postgres command in terminal to output very large query result into CSV format:

psql -d ecoprod -t -A -F"," -f queries/query.sql > exports/output.csv

It works just fine except its not valid CSV format. Text values should be wrapped in quotes "". Its not and its causing many problems parsing the CSV when there are commas in the text and so on.

Of course I could use another delimiter like semicolon however its the similar problem. In addition some text values contain line break characters which also breaks the parsing.

Didnt find any way to modify the command in documentation. Hope you will help me. Thank you.

-F doesn't promise to generate valid CSV. There is a --csv option you could use instead, which is at least intended for this purpose. But it seems like COPY or \copy would be more suited.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM