xxxxxxxxxx
\copy (SELECT * FROM persons) to 'C:\tmp\persons_client.csv' with csv
xxxxxxxxxx
>psql dbname
psql>\f ','
psql>\a
psql>\o '/tmp/output.csv'
psql>SELECT * from users;
psql>\q
----------------------------------
COPY (SELECT * from users) To '/tmp/output.csv' With CSV;
-----------------------------------------
psql -d dbname -t -A -F"," -c "select * from users" > output.csv
xxxxxxxxxx
-- Client side -This approach does the file handling on the client side
\Copy (Select * From foo) To '/tmp/test.csv' With CSV DELIMITER ',' HEADER
-- Server side - This approach runs entirely on the remote server
Copy (Select * From foo) To '/tmp/test.csv' With CSV DELIMITER ',' HEADER;
copy csv file to postgres table in psql
xxxxxxxxxx
COPY mytable FROM 'data.csv' DELIMITER ',' CSV HEADER;