Re: Support tab completion for upper character inputs in psql

Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: "tanghy.fnst@fujitsu.com" <tanghy.fnst@fujitsu.com>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>, Japin Li <japinli@hotmail.com>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>, Laurenz Albe <laurenz.albe@cybertec.at>, "smithpb2250@gmail.com" <smithpb2250@gmail.com>, "david.zhang@highgo.ca" <david.zhang@highgo.ca>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2022-02-01T13:15:45Z
Lists: pgsql-hackers

Attachments

Tom Lane <tgl@sss.pgh.pa.us> writes:

> I wrote:
>> =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org> writes:
>>> First, as noted in the test, it doesn't preserve the case of the input
>>> for keywords appended to the query result.  This is easily fixed by
>>> using `pg_strdup_keyword_case()`, per the first attached patch.
>
>> I thought about that, and intentionally didn't do it, because it
>> would also affect the menus produced by tab completion.
>> ...
>> We could do something hacky like matching case only when there's
>> no longer any matching object names, but that might be too magic.
>
> I experimented with that, and it actually doesn't seem as weird
> as I feared.  See if you like this ...

That's a reasonable compromise, and the implementation is indeed less
hacky than one might have feared.  Although I think putting the
`num_keywords` variable before `num_other` would read better.

Going through the uses of COMPLETE_WITH(_SCHEMA)_QUERY_PLUS, I noticed a
few that had the keywords in lower case, which is fixed in the attached
patch (except the hardcoded data types, which aren't really keywords).
While I was there, I also added completion of "AUTHORIZATION" after
"SHOW SESSSION", which is necessary since there are variables starting
with "session_".

> 			regards, tom lane

Cheers,
- ilmari

Commits

  1. Fix minor memory leaks in psql's tab completion.

  2. Further tweaks for psql's new tab-completion logic.

  3. Treat case of tab-completion keywords a bit more carefully.

  4. psql: improve tab-complete's handling of variant SQL names.

  5. Make PQcancel use the PGconn's tcp_user_timeout and keepalives settings.

  6. Use a WaitLatch for vacuum/autovacuum sleeping