Re: Correct handling of blank/commented lines in PSQL interactive-mode history

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Greg Nancarrow <gregn4422(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Correct handling of blank/commented lines in PSQL interactive-mode history
Date: 2021-11-29 08:07:48
Message-ID: ce61f12d870d56948686d2cfa8333957954a6518.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 2021-11-27 at 18:30 -0500, Tom Lane wrote:
> Trying to gather together the various issues mentioned on this thread,
> I see:
>
> * Initial input lines that are blank (whitespace, maybe including a
> comment) are merged into the next command's history entry; but since
> said lines don't give rise to any text sent to the server, there's
> not really any reason why they couldn't be treated as text to be
> emitted to the history file immediately.  This is what Greg originally
> set out to change.  After my experiments mentioned above, I'm quite
> doubtful that his patch is correct in detail (I'm afraid that it
> probably emits stuff too soon in some cases), but it could likely be
> fixed if we could just get agreement that a change of that sort is OK.

For me, it is just a mild annoyance to have unrelated comments
preceding the query be part of the query's history file entry.
If that is difficult to improve, I can live with it the way it is.

> * It's not great that dash-dash comments aren't included in what we
> send to the server.  However, changing that is a lot trickier than
> it looks.  I think we want to continue suppressing comments that
> precede the query proper.  Including comments that are within the
> query text (ahead of the trailing semi) is not so hard, but comments
> following the semicolon look too much like comments-ahead-of-the-
> next-query.  Perhaps that issue should be left for another day ...
> although it does feel like it interacts with the first point.

If we treat double-dash comments differently from /* */ ones,
that is indeed odd. I personally haven't been bothered by it, though.

> * Misbehavior of M-# was also mentioned.  Does anyone object to
> the draft patch I posted for that?

No, I think that is a clear improvement.

There was one other problem mentioned in the original mail, and that
seems to be the most serious one to me:

> psql
psql (14.1)
Type "help" for help.

test=> \set HISTCONTROL ignorespace
test=> -- line that starts with space
test=> SELECT 42;
?column?
══════════
42
(1 row)

Now that query is not added to the history file at all.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message houzj.fnst@fujitsu.com 2021-11-29 08:51:35 RE: Data is copied twice when specifying both child and parent table in publication
Previous Message Michael Paquier 2021-11-29 08:04:01 Re: GUC flags