\copy users TO 'users.csv' CSV HEADER

Category: Databases & SQL

\copy users TO 'users.csv' CSV HEADER

Export a table to a CSV file

A psql meta-command that runs COPY on the client side: it reads the users table and writes users.csv on the machine where psql runs. HEADER adds column names as the first row. Related: \copy users FROM 'users.csv' CSV HEADER imports it back, while server-side COPY writes to the database host's filesystem.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.