Re: BUG #14916: psql \r is invalid in PostgreSQL 10

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "xyh(at)nvn(dot)xyz" <xyh(at)nvn(dot)xyz>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14916: psql \r is invalid in PostgreSQL 10
Date: 2017-11-17 14:53:36
Message-ID: 21696.1510930416@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thursday, November 16, 2017, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us
> <javascript:_e(%7B%7D,'cvml','tgl(at)sss(dot)pgh(dot)pa(dot)us');>> wrote:
>> Please say why you think this is "invalid". I'm pretty sure
>> it was an intentional behavioral change (associated with the
>> rewrite to support \if). In any case it's not obviously worse
>> than before. \r is supposed to clear the current query input
>> string; it says nothing about deleting history.

> Actually, \r is behaving the same. The behavior of \p has been changed (at
> least per the docs) to print the last executed query if the current buffer
> is empty. This behavior change doesn't seem to be in the release notes.

No, it's always done that; the docs are just more clear about it now
(cf. commit 68dba97a4). This works the same in all versions of psql
back to perhaps 7.0:

regression=# select 2+2;
?column?
----------
4
(1 row)

regression=# \p
select 2+2;

and for that matter so does this:

regression=# select 2+2;
?column?
----------
4
(1 row)

regression=# \p
select 2+2;
regression=# select 2+1
regression-# \r
Query buffer reset (cleared).
regression=# \p
select 2+2;
regression=# \g
?column?
----------
4
(1 row)

What's different is that \r used to be willing to clear the previous-query
buffer if the current-query buffer was empty:

regression=# select 2+2;
?column?
----------
4
(1 row)

regression=# \p
select 2+2;
regression=# \r
Query buffer reset (cleared).
regression=# \p
Query buffer is empty.
regression=# \g
regression=#

That was surprising, undocumented, and (AFAICT) an accidental result of
some weird coding rather than anything the code actually intended to do.
So we changed it:

regression=# select 2+2;
?column?
----------
4
(1 row)

regression=# \r
Query buffer reset (cleared).
regression=# \p
select 2+2;
regression=# \g
?column?
----------
4
(1 row)

There was nothing to document since the docs never explained the old
behavior anyway. Maybe there should have been a release note entry
about it, but I don't see how such an entry could be much shorter
than what I just wrote, and it didn't seem worth it.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-11-17 14:59:25 Re: psql ignores server port setting through alter system when connecting?
Previous Message Michael Paquier 2017-11-17 13:58:07 Re: BUG #14917: process hang on create index