Re: \gexec \watch

From: David Fetter <david(at)fetter(dot)org>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: \gexec \watch
Date: 2018-12-06 02:43:10
Message-ID: 20181206024310.GD16928@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Dec 05, 2018 at 07:50:23PM -0300, Alvaro Herrera wrote:
> I just noticed that using \watch after \gexec does not do what I would
> like it to do, namely re-execute the returned queries. Instead, it
> executes the returned queries once, then it just returns the queries.
> That is:
>
> =# select 'select now()' \gexec \watch
> 2018-12-05 19:46:04.928995-03
>
> select now()
>
> select now()
>
> select now()
>
> (This is under \pset tuples_only)
>
> I think to be really useful, this combination ought to work like this
> instead:
>
> =# select 'select now()' \gexec \watch
> 2018-12-05 19:47:51.045574-03
>
> 2018-12-05 19:47:52.152132-03
>
> 2018-12-05 19:47:53.099486-03
>
> Is any psql hacker interested in fixing this?

As far as I can tell, what is happening currently is correct.

\g is a way to say "semicolon," in the sense that it looks backward to
the beginning of an SQL statement, sends it off to the backend, and
returns the results. Once those results are returned, its job is done,
and it releases control to the next psql event along with the memory
of the query it executed, so a following \g (or other "semicolon") can
do something new with it.

\gexec is a slightly different flavor of "semicolon." It starts off
doing what \g does, then before yielding control, it stores the
results and executes those results as a own query. At this point, psql
has forgotten about the results, even though it remembers the query.

\watch is yet another flavor of "semicolon." As with \g, it notices
the previous (or remembered) SQL had been written and executes it.
Unlike \gexec, it doesn't notice the result set. Instead, it repeats
that query in an infinite loop.

There's a bit of a philosophical issue here, or a mathematical one,
whichever way you want to put it. Does it actually make sense to have
the behavior of one "semicolon" spill onto another?

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2018-12-06 03:18:54 Re: on or true
Previous Message Amit Langote 2018-12-06 02:34:19 Re: error message when subscription target is a partitioned table