Re: csv format for psql

From: "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: csv format for psql
Date: 2018-04-06 03:46:34
Message-ID: 431A3C8D-BDE8-42BA-AAE7-B21C892B36B2@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> On Apr 5, 2018, at 11:08 PM, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)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.

Jonathan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2018-04-06 04:08:30 Re: WIP: a way forward on bootstrap data
Previous Message Tom Lane 2018-04-06 03:41:53 Re: WIP: a way forward on bootstrap data