Export PostgreSQL table to CSV [COPY command]

As PostgreSQL COPY command is convenient, I wrote this tips.
This command is easy and really useful, so please try it.

1
$ psql
1
2
-- Export product table to CSV file
\copy (SELECT * FROM products ORDER BY id) TO '/tmp/produccts.csv' DELIMITER ',' CSV HEADER
1
2
# If you want to see the csv including Shift-JIS(Japanese)
nkf -s /tmp/products.csv > /tmp/converted.csv

Special Thanks