Re: csv format for psql

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Daniel Verite <daniel(at)manitou-mail(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: csv format for psql
Date: 2018-03-07 19:30:33
Message-ID: CAFj8pRBrZuJ2-aQd9gwoX4DY_RCxj6bFFWmx05-BbA8cTqW3xg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2018-03-07 20:25 GMT+01:00 David Fetter <david(at)fetter(dot)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
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Verite 2018-03-07 20:00:20 Re: csv format for psql
Previous Message David Fetter 2018-03-07 19:25:54 Re: csv format for psql