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

From: Noboru Saito <noborusai(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Separate the result of \watch for each query execution (psql)
Date: 2022-02-21 05:19:18
Message-ID: CAAM3qn+z8ZvM1sofWD6vm1DbttoLhq-VqvcrtUwHurqFDB0nig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
psql-watch.diff text/x-patch 536 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2022-02-21 05:34:53 Re: Design of pg_stat_subscription_workers vs pgstats
Previous Message Amit Kapila 2022-02-21 05:10:09 Re: Design of pg_stat_subscription_workers vs pgstats