Re: csv format for psql - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: csv format for psql
Date
Msg-id CAFj8pRBrZuJ2-aQd9gwoX4DY_RCxj6bFFWmx05-BbA8cTqW3xg@mail.gmail.com
Whole thread Raw
In response to Re: csv format for psql  (David Fetter <david@fetter.org>)
List pgsql-hackers


2018-03-07 20:25 GMT+01:00 David Fetter <david@fetter.org>:
On Wed, Mar 07, 2018 at 08:04:05PM +0100, Fabien COELHO wrote:
>
> >>  psql --csv -c 'TABLE foo' > foo.csv
> >>
> >>With a -c to introduce the command.
> >
> >This seems pretty specialized.  If we're adding something new, how about
> >
> >   psql --format=csv -o foo.csv -c 'TABLE foo'
> >
> >Or we could stick with:
> >
> >   psql -P format=csv -o foo.csv -c 'TABLE foo'
>
> Currently "-P format=csv" uses the unaligned formating separators, i.e. '|'
> is used. I was suggesting that a special long option could switch several
> variables to some specific values, i.e.
>
>   --csv
>
> Would be equivalent to something like:
>
>   -P format=csv -P fieldsep=, -P recordsep=\n (?) -P tuples_only=on ...

We have some inconsistency here in that fewer table formats are
supported, but I think asciidoc, etc., do this correctly via
invocations like:

    psql -P format=asciidoc -o foo.adoc -AtXc 'TABLE foo'

> I.e. really generate some csv from the data in just one option, not many.
>
> But this is obviously debatable.

I suspect we'll get requests for an all-JSON option, HTML tables,
etc., assuming we don't have them already.

I'm hoping we can have that all in one framework.  I get that setting
each of tuples_only, fieldsep, recordsep, etc.  might be a bit of a
lift for some users, but it's not clear how we'd make a sane default
that made choices among those correct for enough users.

For example, do we know that we want tuples_only behavior by default?
A lot of people's CSV tools assume a header row.

I am for default header - it can be disabled by -t option

Pavel
 

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: csv format for psql
Next
From: "Daniel Verite"
Date:
Subject: Re: csv format for psql