From 9c53e2ba1020d09fcec21e4ded88e88b27f3aa23 Mon Sep 17 00:00:00 2001 From: Astaroth Date: Tue, 5 Dec 2017 15:44:49 -0300 Subject: [PATCH] improved command to export query result to csv file --- cheat/cheatsheets/psql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cheat/cheatsheets/psql b/cheat/cheatsheets/psql index 89a545a..fed3a21 100644 --- a/cheat/cheatsheets/psql +++ b/cheat/cheatsheets/psql @@ -16,8 +16,9 @@ psql -U postgres -d dbName -c 'select * from tableName;' -o fileName # Execute query and get tabular html output: psql -U postgres -d dbName -H -c 'select * from tableName;' -# Execute query and save resulting rows to csv file: -psql -U postgres -d dbName -t -A -P fieldsep=',' -c 'select * from tableName;' -o fileName.csv +# Execute query and save resulting rows to csv file +# (if column names in the first row are not needed, remove the word 'header'): +psql -U postgres -d dbName -c 'copy (select * from tableName) to stdout with csv header;' -o fileName.csv # Read commands from file: psql -f fileName