Re: Separate the result of \watch for each query execution (psql) - Mailing list pgsql-hackers
From | Noboru Saito |
---|---|
Subject | Re: Separate the result of \watch for each query execution (psql) |
Date | |
Msg-id | CAAM3qnK7frW+6af_iET-h=mDPJLfhd-4FgX4ZzzBauqJc0HFXQ@mail.gmail.com Whole thread Raw |
In response to | Re: Separate the result of \watch for each query execution (psql) (Pavel Stehule <pavel.stehule@gmail.com>) |
Responses |
Re: Separate the result of \watch for each query execution (psql)
|
List | pgsql-hackers |
Thank you for your reply. 2022年2月21日(月) 14:52 Pavel Stehule <pavel.stehule@gmail.com>: > > Hi > > po 21. 2. 2022 v 6:19 odesílatel Noboru Saito <noborusai@gmail.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 maybeother, that ending result can significantly increase robustness and can reduce code. I think it can be better to useform 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 helpa lot. > > Regards > > Pavel Thank you.
pgsql-hackers by date: