Exporting csv file from postgresql database server to local machine

Viewed 189

I'm trying to download the select output query as a csv file into my local machine, from the server where the database is stored. I tried using the \copy command :

\copy (SELECT COUNT(*) FROM table) to 'C:\Folder\temp.csv' With CSV DELIMITER ',' HEADER;

It gives output COPY 1 in the terminal, but doesn't generate any csv file in the location. Would really appreciate any help, thanks !

1 Answers

You're closing the file path with a ` instead of with a ', so I guess there is a file somewhere with different name than the one you're expecting ;) Otherwise the command is just fine

\copy (SELECT COUNT(*) FROM t) TO 'C:\Folder\temp.csv' WITH CSV DELIMITER ',';
Related