From: | Greg Nancarrow <gregn4422(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Correct handling of blank/commented lines in PSQL interactive-mode history |
Date: | 2021-09-06 14:13:35 |
Message-ID: | CAJcOf-cAdMVr7azeYR7nWKsNp7qhORzc84rV6d7m7knG5Hrtsw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
Single lines entered in PSQL interactive-mode, containing just
whitespace or an SQL comment ("--..."), don't seem to be stored
correctly in the history.
For example, such lines are currently prepended to the history of the
next command entered, rather than having their own history entry.
Also, if HISTCONTROL=ignorespace is in effect, if a line is entered
that starts with a space and the rest of the line is whitespace or an
SQL comment, then it prevents the next command entered from being
saved in the history.
I've attached a patch that corrects the behaviour.
For the type of lines mentioned, the patch makes the history behave
more like Bash history.
[I noticed this problem in PSQL interactive-mode history when typing
in a long SQL command which I then decided to just comment, using a
"--" prefix, and enter it, to store it in the history, so I could
later recall it from the history after first executing some other
commands.]
Below are some examples of problem scenarios, and results BEFORE/AFTER
the patch is applied:
(1)
<space><ENTER>
SELECT 1;<ENTER>
BEFORE PATCH:
Results in a single history entry, with <space> on the 1st line and
"SELECT 1;" on the 2nd line.
AFTER PATCH:
Results in two history entries, 1st contains <space> and the 2nd
contains "SELECT 1;".
(2)
-- my comment<ENTER>
SELECT 1;<ENTER>
BEFORE PATCH:
Results in a single history entry, containing "-- my comment" on the
1st line and "SELECT 1;" on the 2nd line.
AFTER PATCH:
Results in two history entries, 1st contains "-- my comment" and the
2nd contains "SELECT 1;".
(3)
{--variable=HISTCONTROL=ignorespace}
<space><ENTER>
SELECT 1;<ENTER>
BEFORE PATCH:
No history entry is saved.
AFTER PATCH:
Results in one history entry, containing "SELECT 1;".
(4)
{--variable=HISTCONTROL=ignorespace}
<space>-- my comment<ENTER>
SELECT 1;<ENTER>
BEFORE PATCH:
No history entry is saved.
AFTER PATCH:
Results in one history entry, containing "SELECT 1;".
Regards,
Greg Nancarrow
Fujitsu Australia
Attachment | Content-Type | Size |
---|---|---|
v1-0001-Correct-handling-of-blank-or-commented-lines-in-PSQL-in.patch | application/octet-stream | 2.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2021-09-06 14:50:15 | Re: Correct handling of blank/commented lines in PSQL interactive-mode history |
Previous Message | Pavel Luzanov | 2021-09-06 14:10:51 | Re: psql: \dl+ to list large objects privileges |