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.
Export data from a table to CSV file using the \copy command. In case you have the access to a remote PostgreSQL database server, but you don't have sufficient privileges to write to a file on it, you can use the PostgreSQL built-in command \copy . The \copy command basically runs the COPY statement above.
In PgAdmin export option is available in file menu. Execute the query, and then we can view the data in the Output pane. Click on the menu FILE -> EXPORT from query window.
Step 1: Visit your schema section and select the table you wish to export. Step 2: Right-click on the table name to show up the available options. Step 3: Select the “Import/Export” option. When you click on it, the export data pgAdmin window will appear.
Use psql and redirect stream to file:
psql -U <USER> -d <DB_NAME> -c "COPY <YOUR_TABLE> TO stdout DELIMITER ',' CSV HEADER;" > file.csv
COPY your_table TO '/path/to/your/file.csv' DELIMITER ',' CSV HEADER;
For more details go to this manual
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With