Correct handling of blank/commented lines in PSQL interactive-mode history - Mailing list pgsql-hackers

From Greg Nancarrow
Subject Correct handling of blank/commented lines in PSQL interactive-mode history
Date
Msg-id CAJcOf-cAdMVr7azeYR7nWKsNp7qhORzc84rV6d7m7knG5Hrtsw@mail.gmail.com
Whole thread Raw
Responses Re: Correct handling of blank/commented lines in PSQL interactive-mode history  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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

pgsql-hackers by date:

Previous
From: Pavel Luzanov
Date:
Subject: Re: psql: \dl+ to list large objects privileges
Next
From: "David G. Johnston"
Date:
Subject: Re: Correct handling of blank/commented lines in PSQL interactive-mode history