Using psql to export data

suggest change

Data can be exported using copy command or by taking use of command line options of psql command.

To Export csv data from table user to csv file:

psql -p \<port> -U \<username> -d \<database> -A -F<delimiter> -c\<sql to execute> \> \<output filename with path>

psql -p 5432 -U postgres -d test_database -A -F, -c "select * from user" > /home/user/user_data.csv

Here combination of -A and -F does the trick.

-F is to specify delimiter

-A or --no-align

Switches to unaligned output mode. (The default output mode is otherwise aligned.)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents