Re: psql \G command -- send query and output using extended format

From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql \G command -- send query and output using extended format
Date: 2008-04-04 22:15:29
Message-ID: 758d5e7f0804041515j35a2b7f7g34cc46ed977b8899@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Thu, Apr 3, 2008 at 6:44 PM, Alvaro Herrera
<alvherre(at)commandprompt(dot)com> wrote:
> Bruce Momjian escribió:
>
>
> > It seems more helpful if there were \x option to use extended format
> > only when the output is too wide. TODO already has:
> >
> > o Add auto-expanded mode so expanded output is used if the row
> > length is wider than the screen width.
> >
> > Consider using auto-expanded mode for backslash commands like \df+.
>
> Some sort of "\x auto"? Sounds interesting ...

Hmm, seems doable.

While writing the \G patch I wanted to keep the changes to minimum, so it would
be clear what gets done. What I don't like about that patch is that
I've added in
struct _printTableOpt another bool "extend_once" after the "extend" bool.

I think there should be a format Enum, which would take values like NORMAL,
EXTENDED, and EXTENDED_ONCE -- but this would be a much more invasive patch.
Oh, and coincidentally its where AUTO format should go. :)

Now, assuming we want "\x auto" there are couple of things to discuss
before actually coding.

1. Adding "\x auto" changes how "\x" (and \pset). Currently we accept:
\x - toggle between on and off
\x off - turn extended format off
\x anything - turn extended format on.
if doing, auto we need to change it to something like,
\x - toggle between on and off, if in "auto", toggle to "off"
\x on - extended format on
\x off - extended format off
\x auto - auto extended format
\x anything else - extended format on with a "depreciated" warning.

2. Do we want \G? I would say "yes". ;) But it should get discussed.
pgsql-general perhaps?

3. We should decide how each of the "commands" work in auto mode.
I think it should be something like: "if output is less or equal than
screen width -- use normal mode, else extended". I we have \g and \G,
they should be handled a bit differently in auto mode:
";" -- perform automatic format adjustment
"\g" -- force normal mode (probably for file-output)
"\G" -- force extended mode (probably for file-output).
I especially would like an opinion on this from you.

4. And as for using "\x" for the one-shot expanded output, I think it would
be possible to allow queries like:
SELECT * FROM foo\x
...but I think fundamental problem with this approach is that it promotes
"\x" to be able to submit query. I don't think its a good idea.

Regards,
Dawid

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2008-04-04 22:20:10 Re: modules
Previous Message Teodor Sigaev 2008-04-04 21:53:41 Re: Garbage pad bytes within datums are bad news

Browse pgsql-patches by date

  From Date Subject
Next Message Alvaro Herrera 2008-04-04 22:30:33 Re: psql \G command -- send query and output using extended format
Previous Message Pavel Stehule 2008-04-04 21:09:59 fixing sql generated features - plpgsql case statement