Re: patch to add \watch to psql

From: Daniel Farina <daniel(at)heroku(dot)com>
To: Will Leinweber <will(at)heroku(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Abhijit Menon-Sen <ams(at)2ndquadrant(dot)com>
Subject: Re: patch to add \watch to psql
Date: 2013-01-18 01:07:03
Message-ID: CAAZKuFaNaKdnkx-dVmAiPn3HdSaNLa7E2FWWvwh6a7FciHDsbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have adjusted this patch a little bit to take care of the review
issues, along with just doing a bit of review myself.

On Thu, Oct 25, 2012 at 2:25 AM, Will Leinweber <will(at)heroku(dot)com> wrote:
> Thanks for the reviews and comments. Responses inline:
> .
> On Sat, Oct 20, 2012 at 9:19 AM, Abhijit Menon-Sen <ams(at)2ndquadrant(dot)com> wrote:
>> Maybe you should call it \repeat or something. I'm sure people would get
>> around to using \watch that way eventually. :-)
>
>
> While I agree that clearing the screen would be nicer, I feel that
> watching the bottom of the screen instead of the top gets you 95% of
> the value of unix watch(1), and having the same name will greatly
> enhance discoverability. Perhaps later on if ncurses is linked for
> some other reason, this could take advantage of it then.
>
> That said, I'm not that strongly attached to the name one way or the other.

The name \repeat has grown on me, but I haven't bothered renaming it
for the time being. I think sameness with the familiar 'watch'
program may not be such a big deal as I thought originally, but
'repeat' sounds a lot more like a kind of flow control for scripts,
whereas \watch is more clearly for humans, which is the idea.

> On Wed, Oct 24, 2012 at 2:55 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>> This doesn't handle multiline queries:
>>
>> => \watch select 1 +
>> ERROR: 42601: syntax error at end of input
>> LINE 1: select +
>> ^
>>
>> I think to make it cooperate better with psql syntax, put the \watch at
>> the end, as a replacement for \g, like

I have implemented some kind of multi-line support. The rough part is
in this part of the patch:

+ if (query_buf && query_buf->len > 0)
+ {
+ /*
+ * Check that the query in query_buf has been terminated. This
+ * is mostly consistent with behavior from commands like \g.
+ * The reason this is here is to prevent terrible things from
+ * occuring from submitting incomplete input of statements
+ * like:
+ *
+ * DELETE FROM foo
+ * \watch
+ * WHERE....
+ *
+ * Wherein \watch will go ahead and send whatever has been
+ * submitted so far. So instead, insist that the user
+ * terminate the query with a semicolon to be safe.
+ */
+ if (query_buf->data[query_buf->len - 1] == ';')

What I found myself reaching for when giving up and writing this hack
was a way to thread through the last lexer state of query_buf, which
seems it could stand to be accrue a bit more information than being
just a byte buffer. But this is the simplest possible thing, so I'll
let others comment...

--
fdr

Attachment Content-Type Size
psql-watch-v2.patch.gz application/x-gzip 2.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2013-01-18 01:13:16 Re: Event Triggers: adding information
Previous Message Tatsuo Ishii 2013-01-18 00:43:32 Re: review: pgbench - aggregation of info written into log