Export Postgres Database into CSV file

后端 未结 7 1954
醉梦人生
醉梦人生 2021-01-29 23:11

I want to export a Postgres database into a CSV file. Is this possible?

If it is possible, then how can I do this? I have seen that we can convert a particular table into

7条回答
  •  孤独总比滥情好
    2021-01-29 23:28

    You can use this at psql console:

    \copy (SELECT foo,bar FROM whatever) TO '/tmp/file.csv' DELIMITER ',' CSV HEADER
    

    Or it in bash console:

    psql -P format=unaligned -P tuples_only -P fieldsep=\, -c "SELECT foo,bar FROM whatever" > output_file
    

提交回复
热议问题