Search code examples
postgresqlcsvexport-to-csv

export table to csv on postgres


How can I export a table to .csv in Postgres, when I'm not superuser and can't use the copy command?

I can still import the data to postgres with "import" button on the right click, but no export option.


Solution

  • Use psql and redirect stream to file:

    psql -U <USER> -d <DB_NAME> -c "COPY <YOUR_TABLE> TO stdout DELIMITER ',' CSV HEADER;" > file.csv