Re: csv format for psql

Jonathan S. Katz <jkatz@postgresql.org>

From: "Jonathan S. Katz" <jkatz@postgresql.org>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, Fabien COELHO <coelho@cri.ensmp.fr>, Isaac Morland <isaac.morland@gmail.com>, Daniel Verite <daniel@manitou-mail.org>, "David G. Johnston" <david.g.johnston@gmail.com>, David Steele <david@pgmasters.net>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2018-04-06T12:43:59Z
Lists: pgsql-hackers
Hi Pavel,

> On Apr 6, 2018, at 1:38 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> 
> 
> 
> 2018-04-06 5:46 GMT+02:00 Jonathan S. Katz <jkatz@postgresql.org <mailto:jkatz@postgresql.org>>:
> 
> > On Apr 5, 2018, at 11:08 PM, Peter Eisentraut <peter.eisentraut@2ndquadrant.com <mailto:peter.eisentraut@2ndquadrant.com>> wrote:
> >
> > On 4/1/18 03:27, Pavel Stehule wrote:
> >> I don't share option so CSV format should be exactly same like CSV COPY.
> >> COPY is designed for backups - and header is not too important there.
> >> When I seen some csv, then there usually header was used.
> >
> > I think in practice a lot of people use COPY also because it's a nice
> > way to get CSV output, even if it's not for backups.  The options that
> > COPY has for CSV are clearly designed around making the output
> > compatible with various CSV-variants.
> 
> +1
> 
> From a user standpoint this was mostly how I use COPY.  Someone
> requests a report that they can manipulate in $SPREADSHEET.  I write
> a query, place it inside a “COPY” statement with FORMAT CSV,
> HEADER TRUE, save to file, and deliver.
> 
> > Another thought: Isn't CSV just the same as unaligned output plus some
> > quoting?  Could we add a quote character setting and then define --csv
> > to be quote-character = " and fieldsep = , ?
> 
> This makes a lot of sense. I’ve also generated CSV files using a
> combination of:
> 
>         \f ,
>         \a
>         \o file.csv
> 
> and then running the query, but if any of the fields contained a “,” if would
> inevitably break in $SPREADSHEET.
> 
> unfortunately, most used CSV separator in Czech Repuplic is ; due MS Excel settings for CR

Sure.  So in that case with the above, I would have used "\f ;” or
DELIMITER ‘;’ so it sounds like Peter’s suggestion is still valid.

Jonathan

Commits

  1. Add CSV table output mode in psql.

  2. Reorganize format options of psql in alphabetical order

  3. Complete TODO item: