Exporting CSV from psql.

\f ','
\a
\t
\o some/path.csv

and then run the query. \f sets the field separator, \a sets format to “unaligned”, \t sets “only tuples”. Upon executing the query, the output is written rather than displayed.rN1


  1. Jakub Neander, “How To Export PostgreSQL Query Output as CSV,” zaiste.net, accessed January 5, 2022, https://zaiste.net/databases/postgresql/howtos/howto-export-postgresql-query-output-csv/. (See notes.)