+2 votes
in Databases by (74.8k points)
I want to create a CSV file using the output of SELECT query. How can I export the output?

1 Answer

+2 votes
by (364k points)
selected by
 
Best answer

Use 'copy' command to copy the output to a CSV file. Here is an example to create tab delimited CSV file.

\copy (SELECT * FROM table_name) to 'path_to_file/filename.csv' WITH DELIMITER E'\t' CSV HEADER QUOTE E'\b';


...