Custom Search

SUBSCRIBE

SUBSCRIBE : 300 + Free Video Tutorials Programming (Python, golang, Julia), DevOps

Tuesday, March 14, 2017

How to save PostgreSQL psql query output to a file

How to save PostgreSQL psql query output to a CSV file

https://www.postgresql.org/docs/current/static/sql-copy.html

=> \copy (select * from audityear) TO '/tmp/test1.csv' (format CSV);
=> \copy (select * from audityear) TO '/tmp/test1.csv' (format CSV, delimiter ',');
=> \copy (select * from audityear) TO '/tmp/test1.csv' (format CSV, delimiter ',', HEADER);

OR

=> \copy (select * from audityear) TO '/tmp/test1.csv' (format TEXT);
=> \copy (select * from audityear) TO '/tmp/test1.csv' (format TEXT, delimiter ',');



OR

=> \copy (select * from audityear) TO '/tmp/test1.csv' WITH CSV
=> \copy (select * from audityear) TO '/tmp/test1.csv' WITH CSV HEADER;


No comments:

Post a Comment