Separate the result of \watch for each query execution (psql) - Mailing list pgsql-hackers

From Noboru Saito
Subject Separate the result of \watch for each query execution (psql)
Date
Msg-id CAAM3qn+z8ZvM1sofWD6vm1DbttoLhq-VqvcrtUwHurqFDB0nig@mail.gmail.com
Whole thread Raw
Responses Re: Separate the result of \watch for each query execution (psql)
List pgsql-hackers
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.

Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Design of pg_stat_subscription_workers vs pgstats
Next
From: Andres Freund
Date:
Subject: Re: Design of pg_stat_subscription_workers vs pgstats