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

1 Answer

+1 vote
by (348k 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';

Related questions


...