Re: psql small improvement patch

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: "Shinoda, Noriyoshi (PN Japan A&PS Delivery)" <noriyoshi(dot)shinoda(at)hpe(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: psql small improvement patch
Date: 2019-12-07 15:19:30
Message-ID: 21df8b50-4661-ac10-5c52-3bcb3063c8d8@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12/7/19 5:23 AM, Shinoda, Noriyoshi (PN Japan A&PS Delivery) wrote:
> Hi, Hackers.
>
> I propose a small improvement to the psql command.
> Currently, psql's help/quit/exit command needs to start from the first position of the prompt.
> For example, if you write a command after a space, the continuation prompt
> (PROMPT2) is displayed.
>
> ---
> postgres=> \set PROMPT2 'continue=>'
> postgres=> <SPACE>help
> continue=>
> ---
>
> The attached patch allows the command to be executed ignoring leading white spaces.

Thank you for the patch. I took a look, and have two concerns.

The smaller concern is that psql uses isspace() to determine whether a
character is whitespace in the current locale, so instead of using
strspn(line, " \t") you might want to use isspace() and be consistent.
On the other hand, there is precedent in other files for what you are
doing, such as in src/fe_utils/print.c:

/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')

My larger concern is that people may be using space before a command
word to avoid having it be interpreted as a command. Take for example
the following contrived psql interaction:

mark=# create table help (str text);
CREATE TABLE
mark=# insert into help (str) values ('foo');
INSERT 0 1
mark=# select * from
mark-# help
mark-# where str is not null;
str
-----
foo
(1 row)

In the current unpatched psql, if I don't indent the second line, I
get cruft in the output:

mark=# select * from
mark-# help
Use \? for help or press control-C to clear the input buffer.
mark-# where str is not null;
str
-----
foo
(1 row)

Patching psql as you propose would result in that cruft whether or
not I indent the second line. We would need to consider if that
behavior change is going to cause more problems for users than your
patch is worth. How common is this problem you are trying to fix?

--
Mark Dilger

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-12-07 16:34:12 Re: verbose cost estimate
Previous Message Andrew Dunstan 2019-12-07 13:51:20 Re: libpq sslpassword parameter and callback function