Re: Support tab completion for upper character inputs in psql
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: tgl@sss.pgh.pa.us
Cc: tanghy.fnst@cn.fujitsu.com, pgsql-hackers@lists.postgresql.org
Date: 2021-02-08T08:02:12Z
Lists: pgsql-hackers
At Sun, 07 Feb 2021 13:55:00 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in
> "Tang, Haiying" <tanghy.fnst@cn.fujitsu.com> writes:
> > When using psql I found there's no tab completion for upper character inputs. It's really inconvenient sometimes so I try to fix this problem in the attached patch.
>
> This looks like you're trying to force case-insensitive behavior
> whether that is appropriate or not. Does not sound like a good
> idea.
Agreed. However I'm not sure what the OP exactly wants, \set behaves
in a different but similar way.
=# \set c[tab]
=# \set COMP_KEYWORD_CASE _
However set doesn't. If it is what is wanted, the following change on
Query_for_list_of_set_vars works (only for the case of SET/RESET
commands).
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 5f0e775fd3..5c2a263785 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -725,7 +725,8 @@ static const SchemaQuery Query_for_list_of_statistics = {
" UNION ALL SELECT 'role' "\
" UNION ALL SELECT 'tablespace' "\
" UNION ALL SELECT 'all') ss "\
-" WHERE substring(name,1,%d)='%s'"
+" WHERE substring(name,1,%1$d)='%2$s' "\
+" OR pg_catalog.lower(substring(name,1,%1$d))=pg_catalog.lower('%2$s')"
#define Query_for_list_of_show_vars \
"SELECT name FROM "\
=# set AP[tab]
=# set application_name _
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Commits
-
Fix minor memory leaks in psql's tab completion.
- 90474c16a7d2 16.0 landed
- 00cf40328a31 15.0 landed
-
Further tweaks for psql's new tab-completion logic.
- f0cd9097cfac 15.0 landed
-
Treat case of tab-completion keywords a bit more carefully.
- 020258fbd30d 15.0 landed
-
psql: improve tab-complete's handling of variant SQL names.
- 02b8048ba5dc 15.0 landed
-
Make PQcancel use the PGconn's tcp_user_timeout and keepalives settings.
- 5987feb70b5b 15.0 cited
-
Use a WaitLatch for vacuum/autovacuum sleeping
- 4753ef37e0ed 14.0 cited