sql - postgresql: Force Quotes on Header -


i try force quotes on header.

copy (     select *     "table" ) <path> csv header force quote *; 

with this, header , in quotes except header. want have exact opposite.

to <path> csv header force quote header; 

and

to <path> csv force quote header; 

did not work.

any idea how manage this?

no such option available in postgresql's copy support, @ least in 9.2 , older. you've observed, headers aren't quoted - or rather, they're in auto-quote mode they're quoted if contain delimiter or other special character:

\copy (select 1 "first value", 2 "second value", 3 "third value, comma") '/tmp/test.csv' (format csv, header true, force_quote *); 

produces:

first value,second value,"third value, comma" "1","2","3" 

you need transform csv via more flexible external tool understands weird , wonderful favours of csv in use, or use external tool produce directly.

in situations write simple perl or python script queries database using perl's dbi , dbd::pg or python's psycopg2 , uses appropriate csv library output desired csv dialect. such scripts tend simple , they're more efficient \copying csv parsing , rewriting it.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -