Re: [PATCH] psql: Add tab completion for \dO, \dc and \det

From: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
To: Shubh Mehta <shubhmehta942(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] psql: Add tab completion for \dO, \dc and \det
Date: 2026-12-04 09:32:03
Message-ID: OS9P286MB6983084A7125D997E062C3D7C5944B2@OS9P286MB698308.JPNP286.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Hi,
>
> When I press TAB after \dO, \dc or \det in psql, it shows table
> names. That is not right. These commands are for collations,
> conversions and foreign tables.
>
> This happens because these three commands don't have their own rule
> in tab-complete.in.c, so they use the "\d*" rule, which lists tables.
>
> This patch adds a rule for each:
>
> \dO -> collation names
> \dc -> conversion names
> \det -> foreign table names
>
> For \dc I added a new Query_for_list_of_conversions. For the other
> two I used the queries that were already there.
>
> I also removed \dc from the TODO comment and added tests for all
> three to the psql tab completion TAP test. All psql tests pass on
> master for me.
>
> Thanks,
> Shubh Mehta

Hi,
I think this patch is useful. These commands currently fall through to the generic \d* completion and offer relation names instead of the objects handled by each command. The patch provides the appropriate completion and also resolves the existing TODO for \dc.
I applied the patch and confirmed that it builds successfully and that all tests pass. The implementation follows the existing tab-completion patterns.
I also manually tested the following cases:

*
completion with the + modifier for \dO, \dc, and \det
*
schema-qualified completion for objects outside the public schema

All cases worked as intended. Since these use existing common infrastructure, I do not think additional TAP tests are necessary.
I found one minor formatting issue in the test setup. The following line exceeds the Perl line-length setting:
. "CREATE CONVERSION test_conversion FOR 'UTF8' TO 'LATIN1' FROM utf8_to_iso8859_1;"

Long SQL strings are split by concatenation elsewhere, for example in 014_binary.pl. This line could similarly be written as:

. "CREATE CONVERSION test_conversion FOR 'UTF8' TO 'LATIN1' "
. "FROM utf8_to_iso8859_1;"

As a separate, non-blocking observation, while looking for existing completion code related to conversions, I found the following entry:

{"CONVERSION", "SELECT conname FROM pg_catalog.pg_conversion WHERE conname LIKE '%s'"},

With a conversion in a non-public schema, the current completion behaves as follows:
Input:
DROP CONVERSION private_schema.sec<Tab>
Completion result:
DROP CONVERSION secret_conversion

The schema name is lost, and the completed command fails because no
conversion with that unqualified name exists in the current search path.

Using the Query_for_list_of_conversions implementation added by this patch, I tried the following entry:
{"CONVERSION", NULL, NULL, &Query_for_list_of_conversions},

The completion then behaved as follows:
Input:
DROP CONVERSION private_schema.sec<Tab>
Completion result:
DROP CONVERSION private_schema.secret_conversion

The schema name is preserved.
This is consistent with commands such as DROP TABLE. If the user lacks permission, the server still rejects the command.
I noticed this while reviewing the existing completion code, so I
wanted to share it as an additional observation. What do you think?

Regards,

Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

________________________________
差出人: Shubh Mehta <shubhmehta942(at)gmail(dot)com>
送信日時: 2026年11月30日 7:06
宛先: pgsql-hackers(at)lists(dot)postgresql(dot)org <pgsql-hackers(at)lists(dot)postgresql(dot)org>
件名: [PATCH] psql: Add tab completion for \dO, \dc and \det

Hi,

When I press TAB after \dO, \dc or \det in psql, it shows table
names. That is not right. These commands are for collations,
conversions and foreign tables.

This happens because these three commands don't have their own rule
in tab-complete.in.c, so they use the "\d*" rule, which lists tables.

This patch adds a rule for each:

\dO -> collation names
\dc -> conversion names
\det -> foreign table names

For \dc I added a new Query_for_list_of_conversions. For the other
two I used the queries that were already there.

I also removed \dc from the TODO comment and added tests for all
three to the psql tab completion TAP test. All psql tests pass on
master for me.

Thanks,
Shubh Mehta

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ilia Evdokimov 2026-12-04 09:34:41 Re: Incorrect selectivity estimates for NOT on nullable boolean columns
Previous Message Ivan Alekseev 2026-12-04 09:22:15 Re: [PATCH] Allow NOTIFY without cross-transaction commit ordering