Re: Separate the result of \watch for each query execution (psql)

From: Noboru Saito <noborusai(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Separate the result of \watch for each query execution (psql)
Date: 2022-02-21 13:23:16
Message-ID: CAAM3qnK7frW+6af_iET-h=mDPJLfhd-4FgX4ZzzBauqJc0HFXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you for your reply.

2022年2月21日(月) 14:52 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
> Hi
>
> po 21. 2. 2022 v 6:19 odesílatel Noboru Saito <noborusai(at)gmail(dot)com> napsal:
>>
>> I need a way to separate the results of \watch for each query execution.
>>
>> There is only a blank line between the results of \watch.
>> However, there is also a blank line after the title, which complicates
>> the rules.
>>
>> My suggestion is to insert a "form feed(\f)" (preferably a newline)
>> before the result and output it.
>> Then, the output will be as follows.
>>
>> # select now(); \watch 1
>> ^L <--- add
>> Thu Feb 17 11:52:05 2022 (every 1s)
>>
>> now
>> -------------------------------
>> 2022-02-17 11:52:05.69394 + 09
>> (1 row)
>>
>> ^L <--- add
>> Thu Feb 17 11:52:06 2022 (every 1s)
>>
>> now
>> ------------------------------
>> 2022-02-17 11:52:06.96906 + 09
>> (1 row)
>>
>> (^L is usually not displayed. It is visualized by passing through a
>> filter such as `less`.)
>>
>> This is possible with the following simple patch.
>>
>> ```
>> diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
>> index d65b9a124f..ee9442d0a6 100644
>> --- a/src/bin/psql/common.c
>> +++ b/src/bin/psql/common.c
>> @@ -646,10 +646,12 @@ PSQLexecWatch(const char *query, const
>> printQueryOpt *opt, FILE *printQueryFout)
>> switch (PQresultStatus(res))
>> {
>> case PGRES_TUPLES_OK:
>> + fprintf(fout, "\f\n");
>> printQuery(res, opt, fout, false, pset.logfile);
>> break;
>>
>> case PGRES_COMMAND_OK:
>> + fprintf(fout, "\f\n");
>> fprintf(fout, "%s\n%s\n\n", opt->title, PQcmdStatus(res));
>> break;
>>
>> ```
>>
>> I am developing a terminal pager ov (https://github.com/noborus/ov).
>> It's a generic pager, but it has features suitable for use with psql.
>>
>> I found that \watch supports PAGER in PostgreSQL 15. That's great.
>>
>> ov can be received and displayed, but I want to display it from the
>> beginning every time it is executed (like pspg).
>>
>> The current output is a bit difficult to clear and display for each result.
>
>
> I strongly agree. It was a lot of work to find a workable solution for pspg. Special chars that starting result and maybe other, that ending result can significantly increase robustness and can reduce code. I think it can be better to use form feed at the end of form - like it is semantic of form feed. You know, at this moment, the result is complete. https://en.wikipedia.org/wiki/Page_break

It's easier to print a form feed before the result, but it's okay at the end.

> I don't think using it by default can be the best. Lot of people don't use specialized pagers, but it can be set by \pset. Form feed should be used on end
>
> \pset formfeed [on, off]

I think it's a good idea to be able to switch with \pset.

> Ascii has few nice characters, that we can use
>
> 1 .. SOX - start of header
> 2 .. STX - start of text
> 3 .. ETX - end of text
>
> Using it, it can reduce some heuristic in pspg, that is not fully 100% when border is not 2.
>
> But implementation of formfeed support can be a very good start. Any mark that can be used for synchronization can help a lot.
>
> Regards
>
> Pavel

Thank you.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2022-02-21 14:10:20 Using Test::More test functions for pg_rewind
Previous Message Peter Eisentraut 2022-02-21 12:49:09 Re: initdb / bootstrap design