Обсуждение: [HACKERS] proposal: psql command \graw

Поиск
Список
Период
Сортировка

[HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:
Hi

I am thinking about printing graphs in psql (mainly some histograms). I found so gnuplot is able do very good graphs in console. The one issue is user friendly (with less steps) generating data in good format for this application. 

One my idea is introduction new simple output format and execution command with result in this format.

It should work something like

\setenv GNUPLOT_OPTION '......'

SELECT * FROM data

\graw | gnuplot ...

It can be used for any other applications R, ggplot, ..

Ideas, comments?

Regards

Pavel

Re: [HACKERS] proposal: psql command \graw

От
Aleksander Alekseev
Дата:
Hi Pavel,

> I am thinking about printing graphs in psql (mainly some histograms). I
> found so gnuplot is able do very good graphs in console. The one issue is
> user friendly (with less steps) generating data in good format for this
> application.
>
> One my idea is introduction new simple output format and execution command
> with result in this format.
>
> It should work something like
>
> \setenv GNUPLOT_OPTION '......'
>
> SELECT * FROM data
>
> \graw | gnuplot ...
>
> It can be used for any other applications R, ggplot, ..
>
> Ideas, comments?

Sounds cool. On the other hand, I think it's kind of too domain specific
task. So I wonder whether it could be generalized somehow so anyone
could write an extension that would export data in any format in a
friendly way.

For instance:

create extension export_to_gnuplot;
select * from data
\export_to_gnuplot | gnuplot ...

--
Best regards,
Aleksander Alekseev

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
Hello Pavel,

> One my idea is introduction new simple output format and execution command
> with result in this format.
>
> It should work something like
>
> \setenv GNUPLOT_OPTION '......'
> SELECT * FROM data
> \graw | gnuplot ...

I understand that it is kind of a shortcut for:
  \pset fieldsep ' '  \pset format unaligned  \pset tuples_only on  -- possibly other settings...  SELECT * FROM data
\g| gnuplot '...'
 

And then you have to persuade gnuplot to take its data from stdin?

-- 
Fabien.



Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-08-22 10:46 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel,

One my idea is introduction new simple output format and execution command
with result in this format.

It should work something like

\setenv GNUPLOT_OPTION '......'
SELECT * FROM data
\graw | gnuplot ...

I understand that it is kind of a shortcut for:

  \pset fieldsep ' '
  \pset format unaligned
  \pset tuples_only on
  -- possibly other settings...
  SELECT * FROM data \g | gnuplot '...'

And then you have to persuade gnuplot to take its data from stdin?

There are some methods





--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-08-22 10:36 GMT+02:00 Aleksander Alekseev <a.alekseev@postgrespro.ru>:
Hi Pavel,

> I am thinking about printing graphs in psql (mainly some histograms). I
> found so gnuplot is able do very good graphs in console. The one issue is
> user friendly (with less steps) generating data in good format for this
> application.
>
> One my idea is introduction new simple output format and execution command
> with result in this format.
>
> It should work something like
>
> \setenv GNUPLOT_OPTION '......'
>
> SELECT * FROM data
>
> \graw | gnuplot ...
>
> It can be used for any other applications R, ggplot, ..
>
> Ideas, comments?

Sounds cool. On the other hand, I think it's kind of too domain specific
task. So I wonder whether it could be generalized somehow so anyone
could write an extension that would export data in any format in a
friendly way.

For instance:

create extension export_to_gnuplot;
select * from data
\export_to_gnuplot | gnuplot ...

you are mixing server side and client side code. Maybe some time we can write psql custom commands.

can be nice to have more pipes in series

so you can do

select * from data
\graw | histogram | gnuplot ...



 

--
Best regards,
Aleksander Alekseev

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:
Hi

2017-08-22 11:22 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:


2017-08-22 10:46 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel,

One my idea is introduction new simple output format and execution command
with result in this format.

It should work something like

\setenv GNUPLOT_OPTION '......'
SELECT * FROM data
\graw | gnuplot ...

I understand that it is kind of a shortcut for:

  \pset fieldsep ' '
  \pset format unaligned
  \pset tuples_only on
  -- possibly other settings...
  SELECT * FROM data \g | gnuplot '...'

And then you have to persuade gnuplot to take its data from stdin?

There are some methods




postgres=# select pocet_muzu + pocet_zen from obce
postgres-# \graw | gnuplot -p -e "set terminal dumb; plot '-' with boxes"

                                                                               
                                                                               
  1.4e+06 +-+-----+-------+-------+--------+-------+-------+-------+-----+-+   
          +       +       +       +        +       +       +       +       +   
          |       *                                            '-' ******* |   
  1.2e+06 +-+     *                                                      +-+   
          |       *                                                        |   
    1e+06 +-+     *                                                      +-+   
          |       *                                                        |   
          |       *                                                        |   
   800000 +-+     *                                                      +-+   
          |       *                                                        |   
          |       *                                                        |   
   600000 +-+     *                                                      +-+   
          |       *                                                        |   
          |       *                                                        |   
   400000 +-+     *                                     *                +-+   
          |       *                                     *            *     |   
   200000 +-+     *                                     *            *   +-+   
          |       *               *                     *            *     |   
          +       * *  *  +**     *  ** ****   *   *  * *  + ***  ****     +   
        0 +-+-----****************************************************---+-+   
        -1000     0      1000    2000     3000    4000    5000    6000    7000 
                                                                               
postgres=# 

 
 


--
Fabien.


Вложения

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
Hello Pavel,

I have added the patch to the next commitfest.

Patch applies, compiles, works.

I'm okay with the names graw/graw+, and for having such short-hands.

Missing break in switch, even if last item and useless, because other
items do it... Also should be added at its place in alphabetical order?

"column_header" is somehow redundant with "tuples_only". Use the
existing one instead of adding a new one?

More generally, ISTM that the same effect could be achieved without
adding a new print function, but by setting more options (separator,
...) and calling an existing print function. If so, I think it would
reduce the code size.

Missing help entry.

Missing non regression tests.

Missing documentation.

-- 
Fabien.



Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:
Hi

2017-08-24 5:50 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel,

I have added the patch to the next commitfest.

Patch applies, compiles, works.

I'm okay with the names graw/graw+, and for having such short-hands.

Missing break in switch, even if last item and useless, because other
items do it... Also should be added at its place in alphabetical order?

I can do
 

"column_header" is somehow redundant with "tuples_only". Use the
existing one instead of adding a new one?

It is different - a result of tuples_only is just tuples - not column names, not title, footer. I needed new special flag for enhancing tuples_only to print column names 
 

More generally, ISTM that the same effect could be achieved without
adding a new print function, but by setting more options (separator,
...) and calling an existing print function. If so, I think it would
reduce the code size.

Maybe, maybe not. removing PRINT_RAW you need to enhance PRINT_UNALIGNED to use one shot parameters and you have to teach it to print column names in tuples_only mode. The code's length will be same. The form of this patch is not final. 
 

Missing help entry.

Missing non regression tests.

Missing documentation.

yes - I wrote it like proof concept - be possible (for me, for others) to verify usability of this commands (and design). I tested it against gnuplot and looks it is works

Regards

Pavel
 


--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
>> "column_header" is somehow redundant with "tuples_only". Use the
>> existing one instead of adding a new one?
>
> It is different - a result of tuples_only is just tuples - not column
> names, not title, footer. I needed new special flag for enhancing
> tuples_only to print column names

I do not understand. If you keep the special print_raw function, it can 
use tuples_only as true for without column names, and false for with 
column names?

>> More generally, ISTM that the same effect could be achieved without
>> adding a new print function, but by setting more options (separator,
>> ...) and calling an existing print function. If so, I think it would
>> reduce the code size.
>
> Maybe, maybe not. removing PRINT_RAW you need to enhance PRINT_UNALIGNED to
> use one shot parameters and you have to teach it to print column names in
> tuples_only mode. The code's length will be same. The form of this patch is
> not final.

Hmmm. Ok. It depends on the change implication on the print unaligned 
function.

-- 
Fabien.



Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-08-24 8:53 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

"column_header" is somehow redundant with "tuples_only". Use the
existing one instead of adding a new one?

It is different - a result of tuples_only is just tuples - not column
names, not title, footer. I needed new special flag for enhancing
tuples_only to print column names

I do not understand. If you keep the special print_raw function, it can use tuples_only as true for without column names, and false for with column names?

yes - in this case you have true.
 


More generally, ISTM that the same effect could be achieved without
adding a new print function, but by setting more options (separator,
...) and calling an existing print function. If so, I think it would
reduce the code size.

Maybe, maybe not. removing PRINT_RAW you need to enhance PRINT_UNALIGNED to
use one shot parameters and you have to teach it to print column names in
tuples_only mode. The code's length will be same. The form of this patch is
not final.

Hmmm. Ok. It depends on the change implication on the print unaligned function.

It is open - I'll wait to winter commitfest for some other ideas, tests, comments - it is topic for PostgreSQL 11, and then there are a time for discussion

Now, I'll be happy if some other people will test it with larger set of applications and send me a feedback.

Regards

Pavel
 


--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
Hello,

> I'll wait to winter commitfest

Argh, sorry, I put it in the September commitfest, and it seems that it 
cannot be changed afterwards.

Maybe you can close it and redeclare it in the commitfest you want?

> for some other ideas, tests, comments - it is topic for PostgreSQL 11, 
> and then there are a time for discussion.

I was rather seeing that as a small patch which could have been processed 
quickly, but if you expect feedback maybe it is better to give it more 
time.

-- 
Fabien.



Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-08-24 17:27 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello,

I'll wait to winter commitfest

Argh, sorry, I put it in the September commitfest, and it seems that it cannot be changed afterwards.

Maybe you can close it and redeclare it in the commitfest you want?

It can be moved
 

for some other ideas, tests, comments - it is topic for PostgreSQL 11, and then there are a time for discussion.

I was rather seeing that as a small patch which could have been processed quickly, but if you expect feedback maybe it is better to give it more time.

I would to verify format, but thank you very much for your interest :)

Regards

Pavel


 


--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
>> Argh, sorry, I put it in the September commitfest, and it seems that it
>> cannot be changed afterwards.
>>
>> Maybe you can close it and redeclare it in the commitfest you want?
>
> It can be moved

Indeed it can. Feel free to move it, then.

-- 
Fabien.



Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:
Hi

2017-08-24 5:50 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel,

I have added the patch to the next commitfest.

Patch applies, compiles, works.

I'm okay with the names graw/graw+, and for having such short-hands.

Missing break in switch, even if last item and useless, because other
items do it... Also should be added at its place in alphabetical order?

"column_header" is somehow redundant with "tuples_only". Use the
existing one instead of adding a new one?

More generally, ISTM that the same effect could be achieved without
adding a new print function, but by setting more options (separator,
...) and calling an existing print function. If so, I think it would
reduce the code size.

Missing help entry.

Missing non regression tests.

Missing documentation.


I hope so I fixed all mentioned issues.

Regards

Pavel
 
--
Fabien.

Вложения

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
Hello Pavel,

> I hope so I fixed all mentioned issues.

Patch applies with a warning:
 > git apply ~/psql-graw-2.patch /home/fabien/psql-graw-2.patch:192: new blank line at EOF. + warning: 1 line adds
whitespaceerrors.
 

Otherwise it compiles. "make check" ok. doc gen ok.

Two spurious empty lines are added before StoreQueryTuple.

Doc: "If <literal>+</literal> is appended to the command name, a column 
names are displayed."

I suggest instead: "When <literal>+</literal> is appended, column names 
are also displayed."

ISTM that you can remove "force_column_header" and just set "tuple_only" 
to what you need, that is you do not need to change anything in function 
"print_unaligned_text".

-- 
Fabien.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-11-09 21:03 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel,

I hope so I fixed all mentioned issues.

Patch applies with a warning:

 > git apply ~/psql-graw-2.patch
 /home/fabien/psql-graw-2.patch:192: new blank line at EOF.
 +
 warning: 1 line adds whitespace errors.

Otherwise it compiles. "make check" ok. doc gen ok.

Two spurious empty lines are added before StoreQueryTuple.

Doc: "If <literal>+</literal> is appended to the command name, a column names are displayed."

I suggest instead: "When <literal>+</literal> is appended, column names are also displayed."

ISTM that you can remove "force_column_header" and just set "tuple_only" to what you need, that is you do not need to change anything in function "print_unaligned_text".

Last point is not possible - I would not to break original tuple only mode.

Pavel

--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-11-09 21:12 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:


2017-11-09 21:03 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel,

I hope so I fixed all mentioned issues.

Patch applies with a warning:

 > git apply ~/psql-graw-2.patch
 /home/fabien/psql-graw-2.patch:192: new blank line at EOF.
 +
 warning: 1 line adds whitespace errors.

Otherwise it compiles. "make check" ok. doc gen ok.

Two spurious empty lines are added before StoreQueryTuple.

Doc: "If <literal>+</literal> is appended to the command name, a column names are displayed."

I suggest instead: "When <literal>+</literal> is appended, column names are also displayed."

ISTM that you can remove "force_column_header" and just set "tuple_only" to what you need, that is you do not need to change anything in function "print_unaligned_text".

Last point is not possible - I would not to break original tuple only mode.


updated patch


 
Pavel

--
Fabien.


Вложения

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
>> ISTM that you can remove "force_column_header" and just set "tuple_only"
>> to what you need, that is you do not need to change anything in function
>> "print_unaligned_text".
>
> Last point is not possible - I would not to break original tuple only mode.

Hmmm... I do not understand. I can see only one use of force_column_header 
in the function:
 -               if (!opt_tuples_only) +               if (!opt_tuples_only || opt_force_column_header)

So I would basically suggest to do:
 my_popt.topt.tuples_only = !pset.g_raw_header;

in the driver. Looking at the detailed code in that function, probably you 
need to set start_table to on when headers are needed and stop_table to 
off for the raw mode anyway?

Maybe I'm missing something, but it looks that it could be made to work 
without adding another boolean.

-- 
Fabien.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-11-10 8:12 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:

ISTM that you can remove "force_column_header" and just set "tuple_only"
to what you need, that is you do not need to change anything in function
"print_unaligned_text".

Last point is not possible - I would not to break original tuple only mode.

Hmmm... I do not understand. I can see only one use of force_column_header in the function:

 -               if (!opt_tuples_only)
 +               if (!opt_tuples_only || opt_force_column_header)

So I would basically suggest to do:

 my_popt.topt.tuples_only = !pset.g_raw_header;

in the driver. Looking at the detailed code in that function, probably you need to set start_table to on when headers are needed and stop_table to off for the raw mode anyway?

Maybe I'm missing something, but it looks that it could be made to work without adding another boolean.

The tuples only cannot be disabled, because then other parts print number of rows

postgres=# \pset format unaligned
Output format is unaligned.

postgres=# select 10 as a, 20 as b;
a|b
10|20
(1 row) ----<<<<<



--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Fabien COELHO
Дата:
Hello,

>> Maybe I'm missing something, but it looks that it could be made to work 
>> without adding another boolean.
>
> The tuples only cannot be disabled, because then other parts print number
> of rows
>
> postgres=# \pset format unaligned
> Output format is unaligned.
>
> postgres=# select 10 as a, 20 as b;
> a|b
> 10|20
> (1 row) ----<<<<<

Argh. Too bad.

I'm not at ease with having two bools which nearly mean the opposite one 
of the other but not exactly... however I'm not sure that there is a 
simpler way out of this, some exception handling is needed one way or the 
other, either within the header or within the footer... Maybe the whole 
topt logic should be reviewed, but that is not the point of this patch.

So I switched the patch to "ready for committer".

-- 
Fabien.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2017-11-10 16:38 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello,

Maybe I'm missing something, but it looks that it could be made to work without adding another boolean.

The tuples only cannot be disabled, because then other parts print number
of rows

postgres=# \pset format unaligned
Output format is unaligned.

postgres=# select 10 as a, 20 as b;
a|b
10|20
(1 row) ----<<<<<

Argh. Too bad.

I'm not at ease with having two bools which nearly mean the opposite one of the other but not exactly... however I'm not sure that there is a simpler way out of this, some exception handling is needed one way or the other, either within the header or within the footer... Maybe the whole topt logic should be reviewed, but that is not the point of this patch.

I don't think so it is not correct - this mean tuples only + header. Probably the best implementation is something three state - all, tuples only, tuples only and header. But it mean much more changes in psql logic - not adequate to size of this patch


So I switched the patch to "ready for committer".

Thank you very much

Regards

Pavel
 

--
Fabien.

Re: [HACKERS] proposal: psql command \graw

От
Robert Haas
Дата:
On Fri, Dec 1, 2017 at 12:16 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Sat, Nov 11, 2017 at 12:57 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
>> 2017-11-10 16:38 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:
>>> So I switched the patch to "ready for committer".
>>
>> Thank you very much
>
> Patch moved to CF 2018-01 with same status: ready for committer.

I vote to reject this patch.  It doesn't do anything that you can't
already do; it just adds some syntactic sugar.  And that syntactic
sugar saves only a handful of keystrokes.  If you want unaligned,
tuples-only mode, you can set it in 5 keystrokes:

rhaas=# \a\t
Output format is unaligned.
Tuples only is on.

If you use this command, it takes 4 keystrokes; instead of ending your
command with a semicolon (1 character) you end it with \graw (5
characters).

Now, granted, \graw lets you set those options for a single command
rather than persistently, but I'm just not very interested in having a
bunch of \g<whatever> options that enable various combinations of
options.  Soon we'll have a thicket of \g variants that force
whichever combinations of options particular developers like to use,
and if \graw is any indication, the \g<whatever> variant won't
necessarily look anything like the normal way of setting those
options.  And that's not easy to fix, either: \graw could be spelled
\gat since it forces \a on and \t on, but somebody's bound to
eventually propose a variant that sets an option that has no
single-character shorthand.

I'm not going to be bitterly unhappy if somebody else decides to
commit this, but to me it looks like it gains us very little.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:
2017-12-01 16:36 GMT+01:00 Robert Haas : > On Fri, Dec 1, 2017 at 12:16 AM, Michael Paquier > wrote: > > On Sat, Nov 11, 2017 at 12:57 AM, Pavel Stehule > wrote: > >> 2017-11-10 16:38 GMT+01:00 Fabien COELHO : > >>> So I switched the patch to "ready for committer". > >> > >> Thank you very much > > > > Patch moved to CF 2018-01 with same status: ready for committer. > > I vote to reject this patch. It doesn't do anything that you can't > already do; it just adds some syntactic sugar. And that syntactic > sugar saves only a handful of keystrokes. If you want unaligned, > tuples-only mode, you can set it in 5 keystrokes: > > rhaas=# \a\t > Output format is unaligned. > Tuples only is on. > > When you don't want to see column names, then it is true. For some usage - like printing via gnuplot you would to see column names - and it cannot be done with current settings. > If you use this command, it takes 4 keystrokes; instead of ending your > command with a semicolon (1 character) you end it with \graw (5 > characters). > > Now, granted, \graw lets you set those options for a single command > rather than persistently, but I'm just not very interested in having a > bunch of \g options that enable various combinations of > options. Soon we'll have a thicket of \g variants that force > whichever combinations of options particular developers like to use, > and if \graw is any indication, the \g variant won't > necessarily look anything like the normal way of setting those > options. And that's not easy to fix, either: \graw could be spelled > \gat since it forces \a on and \t on, but somebody's bound to > eventually propose a variant that sets an option that has no > single-character shorthand. > > I'm not going to be bitterly unhappy if somebody else decides to > commit this, but to me it looks like it gains us very little. > This feature marginal, but I don't thing so it is without any value - It is well usable with gnuplot - and I hope so not only MacOS users will have terminal with graphic possibilities - and then with this feature can emulate notebook interface, Regards Pavel > > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company >

Re: [HACKERS] proposal: psql command \graw

От
Tom Lane
Дата:
Pavel Stehule <pavel.stehule@gmail.com> writes:
> 2017-12-01 16:36 GMT+01:00 Robert Haas <robertmhaas@gmail.com>:
>> I vote to reject this patch.  It doesn't do anything that you can't
>> already do; it just adds some syntactic sugar.  And that syntactic
>> sugar saves only a handful of keystrokes.  If you want unaligned,
>> tuples-only mode, you can set it in 5 keystrokes:

> When you don't want to see column names, then it is true.

If this is "\a\t except we aren't removing column headers", then it
seems like "\graw" is a remarkably misleading name for the functionality.
I'd been assuming, from reading no more than the patch subject line,
was that it was something like "dump the raw field data with no headers,
footers, or separators", with a claimed use-case involving passing bytea
data to some consumer or other.

FWIW, I concur with Robert's assessment, both that the use-case is pretty
thin and that we do not want to get into the business of encouraging a
boatload of \gxxx variants, especially not ones with randomly chosen names.

> For some usage - like printing via gnuplot you would to see column names -
> and it cannot be done with current settings.

That seems like an argument for new pset option(s) to suppress footers
but not headers.  It's not an argument for invoking such options through
a \g variant; that's totally non-orthogonal.

            regards, tom lane


Re: [HACKERS] proposal: psql command \graw

От
Alexander Korotkov
Дата:
On Fri, Dec 1, 2017 at 6:36 PM, Robert Haas wrote: > On Fri, Dec 1, 2017 at 12:16 AM, Michael Paquier > wrote: > > On Sat, Nov 11, 2017 at 12:57 AM, Pavel Stehule > wrote: > >> 2017-11-10 16:38 GMT+01:00 Fabien COELHO : > >>> So I switched the patch to "ready for committer". > >> > >> Thank you very much > > > > Patch moved to CF 2018-01 with same status: ready for committer. > > I vote to reject this patch. It doesn't do anything that you can't > already do; it just adds some syntactic sugar. And that syntactic > sugar saves only a handful of keystrokes. If you want unaligned, > tuples-only mode, you can set it in 5 keystrokes: > > rhaas=# \a\t > Output format is unaligned. > Tuples only is on. > > If you use this command, it takes 4 keystrokes; instead of ending your > command with a semicolon (1 character) you end it with \graw (5 > characters). > > Now, granted, \graw lets you set those options for a single command > rather than persistently, but I'm just not very interested in having a > bunch of \g options that enable various combinations of > options. Soon we'll have a thicket of \g variants that force > whichever combinations of options particular developers like to use, > and if \graw is any indication, the \g variant won't > necessarily look anything like the normal way of setting those > options. And that's not easy to fix, either: \graw could be spelled > \gat since it forces \a on and \t on, but somebody's bound to > eventually propose a variant that sets an option that has no > single-character shorthand. > For sure, bunch of \g options don't look interesting. But I think \graw option would be quite useful if even it would be the only form of \g forever. Our command line client psql have two great features: 1. Output format customization including boards, separators, spacing, title and so on 2. Ability to export data into files or pipes. It's even more powerful with macros enabling you doing cool things with your data in few keystokes. I've couple of examples in my blog, but for sure it's possible to do much more. http://akorotkov.github.io/blog/2015/08/26/psql-gdb-attach/ http://akorotkov.github.io/blog/2016/06/09/psql-graph/ The problem is that it's hard to read arbitrary formatted psql output from external program (not just gnuplot, but even especially written script). I made my scripts read few variations, but it doesn't look feasible to read all the combinations. For sure, it's possible to set format options inside macro, but then it would affect psql format options after execution. This is why I think only one \graw option is just fine, because it produces stable machine-readable output. If even someone need another format, she can write a conversion script and add it to her macro. Thus, I wouldn't like seeing this feature rejected without better alternative proposed. Alternatively, we could introduce ability for single-line format change, allowing to change psql output format options whose are set back to original values after execution of current line. ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company

Re: [HACKERS] proposal: psql command \graw

От
Alexander Korotkov
Дата:
On Mon, Dec 4, 2017 at 11:21 AM, Alexander Korotkov < a.korotkov@postgrespro.ru> wrote: > The problem is that it's hard to read arbitrary formatted psql output from > external program (not just gnuplot, but even especially written script). I > made my scripts read few variations, but it doesn't look feasible to read > all the combinations. For sure, it's possible to set format options inside > macro, but then it would affect psql format options after execution. > > This is why I think only one \graw option is just fine, because it > produces stable machine-readable output. > Oh, I just get that in current state of \graw doesn't produce good machine-readable output. # select '|', '|' \graw ||| Column separator is character which can occur in values, and values aren't escaped. Thus, reader can't correctly divide values between columns in all the cases. So, I would rather like to see \graw to output in csv format with proper escaping. ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:
2017-12-04 9:29 GMT+01:00 Alexander Korotkov : > On Mon, Dec 4, 2017 at 11:21 AM, Alexander Korotkov < > a.korotkov@postgrespro.ru> wrote: > >> The problem is that it's hard to read arbitrary formatted psql output >> from external program (not just gnuplot, but even especially written >> script). I made my scripts read few variations, but it doesn't look >> feasible to read all the combinations. For sure, it's possible to set >> format options inside macro, but then it would affect psql format options >> after execution. >> >> This is why I think only one \graw option is just fine, because it >> produces stable machine-readable output. >> > > Oh, I just get that in current state of \graw doesn't produce good > machine-readable output. > > # select '|', '|' \graw > ||| > > Column separator is character which can occur in values, and values aren't > escaped. Thus, reader can't correctly divide values between columns in all > the cases. So, I would rather like to see \graw to output in csv format > with proper escaping. > current \graw implementation is pretty minimalistic It is interesting topic - the client side csv support. It can simplify lot of things Regards Pavel > ------ > Alexander Korotkov > Postgres Professional: http://www.postgrespro.com > The Russian Postgres Company >

Re: [HACKERS] proposal: psql command \graw

От
Alexander Korotkov
Дата:
Hi!

On Mon, Dec 4, 2017 at 6:42 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
2017-12-04 9:29 GMT+01:00 Alexander Korotkov <a.korotkov@postgrespro.ru>:
On Mon, Dec 4, 2017 at 11:21 AM, Alexander Korotkov <a.korotkov@postgrespro.ru> wrote:
The problem is that it's hard to read arbitrary formatted psql output from external program (not just gnuplot, but even especially written script).  I made my scripts read few variations, but it doesn't look feasible to read all the combinations.  For sure, it's possible to set format options inside macro, but then it would affect psql format options after execution.

This is why I think only one \graw option is just fine, because it produces stable machine-readable output.

Oh, I just get that in current state of \graw doesn't produce good machine-readable output.

# select '|', '|' \graw
|||

Column separator is character which can occur in values, and values aren't escaped.  Thus, reader can't correctly divide values between columns in all the cases.  So, I would rather like to see \graw to output in csv format with proper escaping.

current \graw implementation is pretty minimalistic

It is interesting topic - the client side csv support.

It can simplify lot of things 

So, I see there is no arguing yet that exporting dataset from psql into a pipe in machine-readable format (presumably csv) would be an useful feature.
Are you going to revise your patch that way during this commitfest?
I'm marking this patch as "waiting for author" for now.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company 

Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2018-01-15 18:40 GMT+01:00 Alexander Korotkov <a.korotkov@postgrespro.ru>:
Hi!

On Mon, Dec 4, 2017 at 6:42 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
2017-12-04 9:29 GMT+01:00 Alexander Korotkov <a.korotkov@postgrespro.ru>:
On Mon, Dec 4, 2017 at 11:21 AM, Alexander Korotkov <a.korotkov@postgrespro.ru> wrote:
The problem is that it's hard to read arbitrary formatted psql output from external program (not just gnuplot, but even especially written script).  I made my scripts read few variations, but it doesn't look feasible to read all the combinations.  For sure, it's possible to set format options inside macro, but then it would affect psql format options after execution.

This is why I think only one \graw option is just fine, because it produces stable machine-readable output.

Oh, I just get that in current state of \graw doesn't produce good machine-readable output.

# select '|', '|' \graw
|||

Column separator is character which can occur in values, and values aren't escaped.  Thus, reader can't correctly divide values between columns in all the cases.  So, I would rather like to see \graw to output in csv format with proper escaping.

current \graw implementation is pretty minimalistic

It is interesting topic - the client side csv support.

It can simplify lot of things 

So, I see there is no arguing yet that exporting dataset from psql into a pipe in machine-readable format (presumably csv) would be an useful feature.
Are you going to revise your patch that way during this commitfest?
I'm marking this patch as "waiting for author" for now.

I hope so lot of people invite CSV support on client side. Some like:

psql -c "SELECT * FROM pg_class" --csv --header > pg_class.csv

Client side CSV formatting is significantly better idea. Unfortunately there are not clean how to do it. The basic question is: can we have 2 codes for CSV - server side/client side? If yes, then implementation should be trivial. If not, then I have not any idea.

We are able to generate html/tex/markdown formats on client side. CSV is more primitive, but much more important data format, so it should not be a problem. But I remember some objections related to code duplication.

Regards

Pavel
 

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company 

Re: [HACKERS] proposal: psql command \graw

От
"Daniel Verite"
Дата:
    Pavel Stehule wrote:

> We are able to generate html/tex/markdown formats on client side. CSV is
> more primitive, but much more important data format, so it should not be a
> problem. But I remember some objections related to code duplication.

While experimenting with adding csv as an output format
(similar to unaligned except that it quotes with CSV rules), I find out
that we can already do this:

\o | client-side-program with arguments
or
\o /path/to/file.csv
COPY (select query) TO STDOUT CSV [HEADER] ;
\o

This can be used to route multiple resultsets into multiple programs
or files without the minor drawbacks of \copy (single line
formatting, no variables interpolation), or
psql -c "COPY (query) TO STDOUT.." >file.csv which is a bit rigid
(single redirect).


OTOH I notice that this simpler form with a right-side argument of \g:
 =# COPY (select 1) TO STDOUT CSV HEADER \g /tmp/file.csv
outputs to the console rather into a file. Not sure why it acts
differently than \o and whether it's intentional.

Anyway I think the above sequence with \o already does everything
that is being proposed as an alternative to \graw, or am I missing
something?


What \o + COPY CSV lacks compared to a csv output format
is the ability to export results from meta-commands in csv,
such as \g in \x mode or \gx, \crosstabview, \d, \l...

The other problem with \o |program + COPY CSV is that it's
not easy to discover that combination. It's more obvious if
we have csv explicitly listed as an output format.

I'll post the patch implementing that in a new thread and we'll see
how it goes.


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite


Re: [HACKERS] proposal: psql command \graw

От
Pavel Stehule
Дата:


2018-01-27 15:22 GMT+01:00 Daniel Verite <daniel@manitou-mail.org>:
        Pavel Stehule wrote:

> We are able to generate html/tex/markdown formats on client side. CSV is
> more primitive, but much more important data format, so it should not be a
> problem. But I remember some objections related to code duplication.

While experimenting with adding csv as an output format
(similar to unaligned except that it quotes with CSV rules), I find out
that we can already do this:

\o | client-side-program with arguments
or
\o /path/to/file.csv
COPY (select query) TO STDOUT CSV [HEADER] ;
\o

This can be used to route multiple resultsets into multiple programs
or files without the minor drawbacks of \copy (single line
formatting, no variables interpolation), or
psql -c "COPY (query) TO STDOUT.." >file.csv which is a bit rigid
(single redirect).


OTOH I notice that this simpler form with a right-side argument of \g:
 =# COPY (select 1) TO STDOUT CSV HEADER \g /tmp/file.csv
outputs to the console rather into a file. Not sure why it acts
differently than \o and whether it's intentional.

Anyway I think the above sequence with \o already does everything
that is being proposed as an alternative to \graw, or am I missing
something?

There is one difference, hard to say how much is important - you have to wrap your query to COPY command. That is not too friendly.

Regards

Pavel

 


What \o + COPY CSV lacks compared to a csv output format
is the ability to export results from meta-commands in csv,
such as \g in \x mode or \gx, \crosstabview, \d, \l...

The other problem with \o |program + COPY CSV is that it's
not easy to discover that combination. It's more obvious if
we have csv explicitly listed as an output format.

I'll post the patch implementing that in a new thread and we'll see
how it goes.


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite