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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Noboru Saito <noborusai(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 05:52:18
Message-ID: CAFj8pRAC75ep_XCPjyNe4_VNjMDxz1zb81FFyo=6XKf7pt8WOg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

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]

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2022-02-21 05:55:07 Re: postgres_fdw: commit remote (sub)transactions in parallel during pre-commit
Previous Message Masahiko Sawada 2022-02-21 05:50:46 Re: pg_stat_get_replication_slot and pg_stat_get_subscription_worker incorrectly marked as proretset