psql2csv icon indicating copy to clipboard operation
psql2csv copied to clipboard

psql --csv flag mention

Open kmoppel opened this issue 11 months ago • 1 comments

Maybe woth mentioning in the README that psql for some time already also has a basic support for CSV output via the --csv flag. Can't change the delimiter and custom quoting settings though, for that need to use the COPY.

Postgres docs

$ psql --csv -Xc "select * from pgbench_accounts limit 2"
aid,bid,abalance,filler
1,1,0,                                                                                    
2,1,0,
$ psql -Xc "COPY (select * from pgbench_accounts limit 2) TO stdout WITH ( format csv, delimiter ';', header on)"
aid;bid;abalance;filler
1;1;0;                                                                                    
2;1;0;

kmoppel avatar Jan 22 '25 11:01 kmoppel

@kmoppel thanks for the pointer - I noticed that is is actually possible to change delimiter with --pset:

$ psql --csv --pset=csv_fieldsep=';' -Xc 'select * from pgbench_accounts limit 2'
aid;bid;abalance;filler
1;1;0;
2;1;0;

I can't see any mention of being able to change quoting though

owst avatar Mar 06 '25 17:03 owst