Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 442
Luba Weissmann Avatar asked Dec 19 '13 10:12

Luba Weissmann


People also ask

How do I export a table from PostgreSQL?

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.

How do I export data from PgAdmin 4 to CSV?

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.

How do I export a table from PgAdmin?

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.


2 Answers

Use psql and redirect stream to file:

psql -U <USER> -d <DB_NAME> -c "COPY <YOUR_TABLE> TO stdout DELIMITER ',' CSV HEADER;" > file.csv
like image 89
marvinorez Avatar answered Nov 18 '22 04:11

marvinorez


COPY your_table TO '/path/to/your/file.csv' DELIMITER ',' CSV HEADER;

For more details go to this manual

like image 33
Thusitha Sumanadasa Avatar answered Nov 18 '22 04:11

Thusitha Sumanadasa