Merge pull request #366 from Asta1986/master

improved command to export query result to csv file
This commit is contained in:
Chris Allen Lane 2019-07-01 18:53:44 -04:00 committed by GitHub
commit c50b236b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -16,8 +16,9 @@ psql -U postgres -d dbName -c 'select * from tableName;' -o fileName
# Execute query and get tabular html output: # Execute query and get tabular html output:
psql -U postgres -d dbName -H -c 'select * from tableName;' psql -U postgres -d dbName -H -c 'select * from tableName;'
# Execute query and save resulting rows to csv file: # 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 # (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: # Read commands from file:
psql -f fileName psql -f fileName