Re: Allow default \watch interval in psql to be configured

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: Greg Sabino Mullane <htamfids(at)gmail(dot)com>, Masahiro Ikeda <ikedamsh(at)oss(dot)nttdata(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Allow default \watch interval in psql to be configured
Date: 2025-03-24 12:10:44
Message-ID: 22C0C484-FFFA-4ECC-BDD2-501CB97FCE59@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 21 Mar 2025, at 11:34, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> wrote:

> There are following differences between command input parsing and
> variable value parsing
> 1. empty string is considered as 0 value while parsing command input
> whereas it wiil cause error when setting to a variable.
> #\watch c=1 i=
> Fri 21 Mar 2025 08:27:25 AM IST (every 0s)
>
> ?column?
> ----------
> 1
> (1 row)
> #\set WATCH_INTERVAL
> invalid input syntax for "WATCH_INTERVAL"
>
> That can be considered as an existing bug and maybe fixed later.

An empty interval in command parsing implies "use the default", I don't think
there is a sensical counterpart in parsing actually setting the default value.
I think trying to define the default value without providing a value is an
error condition.

> With this patch, we are doing something unprecedented (at least
> AFAIK); allowing command arguments defaults to be configurable through
> a psql variable (as against an environment variable). I admit that
> configurable through a psql variable is better since it doesn't meddle
> with environment. Glancing through psql documentation, I didn't find a
> lot of command which may need default argument to be configurable.
> Nonetheless we should mention why this is special and set some
> guidance for such future additions - preferrably in code or at least
> in the commit message.

Sure, I'll mention it in the commit message.

> - of rows. Wait the specified number of seconds (default 2) between executions.
> - For backwards compatibility,
> + of rows. Wait the specified number of seconds (defaults to 2 if
> omitted, which can be
> + changed with the variable <xref linkend="app-psql-variables-watch-interval"/>)
> + between executions. For backwards compatibility,
>
> The text in parenthesis is quite long and it's hard to read ...
> seconds between execution. I suggest
> "Wait the specified number of seconds (default 2) between executions.
> The default wait can be changed by setting the variable <xref
> linkend="app-psql-variables-watch-interval"/>."

Fixed.

> + " number of seconds \\watch waits between executing the query buffer\n");
>
> I am feeling that this should mention "default" somewhere - maybe just
> add it before "number of ".

Fixed.

--
Daniel Gustafsson

Attachment Content-Type Size
v8-0001-psql-Make-default-watch-interval-configurable.patch application/octet-stream 9.9 KB
unknown_filename text/plain 1 byte

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Shlok Kyal 2025-03-24 12:11:07 Re: Enhance 'pg_createsubscriber' to retrieve databases automatically when no database is provided.
Previous Message Ashutosh Bapat 2025-03-24 11:41:45 pg_restore documentation and --create/--single-transaction limitation