Make psql ignore trailing semicolons in \sf, \ef, etc

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Make psql ignore trailing semicolons in \sf, \ef, etc
Date: 2024-01-08 20:48:32
Message-ID: 2012251.1704746912@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

We had a complaint (see [1], but it's not the first IIRC) about how
psql doesn't behave very nicely if one ends \sf or allied commands
with a semicolon:

regression=# \sf sin(float8);
ERROR: expected a right parenthesis

This is a bit of a usability gotcha, since many other backslash
commands are forgiving about trailing semicolons. I looked at
the code and found that it's actually trying to ignore semicolons,
by passing semicolon = true to psql_scan_slash_option. But that
fails to work because it's also passing type = OT_WHOLE_LINE,
and the whole-line code path ignores the semicolon flag. Probably
that's just because nobody needed to use that combination back in
the day. There's another user of OT_WHOLE_LINE, exec_command_help,
which also wants this behavior and has written its own stripping
code to get it. That seems pretty silly, so here's a quick finger
exercise to move that logic into psql_scan_slash_option.

Is this enough of a bug to deserve back-patching? I'm not sure.

regards, tom lane

[1] https://www.postgresql.org/message-id/CAEs%3D6D%3DnwX2wm0hjkaw6C_LnqR%2BNFtnnzbSzeZq-xcfi_ooKSw%40mail.gmail.com

Attachment Content-Type Size
ignore-trailing-semi-in-sf-ef-sv-ev.patch text/x-diff 3.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2024-01-08 20:50:47 Re: Emit fewer vacuum records by reaping removable tuples during pruning
Previous Message Joe Conway 2024-01-08 20:40:23 Re: Emitting JSON to file using COPY TO