I\'d like to execute a query from the shell (not in the interactive psql client) and have it print the CSV or TSV representation of the output to STDOUT. How do you do that with
EDITED: Using -F
Use commas via -F and use "unaligned table output mode" -A:
-F
-A
psql my_database -U myuser -A -F , -c "select * from mytable"
You can specify the field separator with the -F command line parameter to psql