Re: \gexec \watch

Поиск
Список
Период
Сортировка
От David Fetter
Тема Re: \gexec \watch
Дата
Msg-id 20181206024310.GD16928@fetter.org
обсуждение исходный текст
Ответ на \gexec \watch  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Ответы Re: \gexec \watch  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Список 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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Amit Langote
Дата:
Сообщение: Re: error message when subscription target is a partitioned table
Следующее
От: Tatsuo Ishii
Дата:
Сообщение: Re: on or true