+2 votes
in Databases by (40.7k 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 (157k points)

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