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
v1-0001-Correct-handling-of-blank-or-commented-lines-in-PSQL-in.patch
Description: Binary data