| From: | Shubh Mehta <shubhmehta942(at)gmail(dot)com> |
|---|---|
| To: | koshino(at)sraoss(dot)co(dot)jp, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] psql: Add tab completion for \dO, \dc and \det |
| Date: | 2026-12-06 16:23:48 |
| Message-ID: | CAP0=POXis5Om6sWgMNAdCiHK96S8wiB4=Qvx1X0whpWG18xsfw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Koshino-san,
Thank you for the review and for testing the patch.
> The following line exceeds the Perl line-length setting
Fixed. I split the CREATE CONVERSION line into two lines, the same way
as you suggested.
> {"CONVERSION", NULL, NULL, &Query_for_list_of_conversions},
I agree, this is better. I tried it and DROP CONVERSION now keeps the
schema name, like DROP COLLATION does. I put this change in a separate
patch (0002), so it can be looked at on its own.
Attached v2:
0001 - same as v1, only the long line in the test is split
0002 - use Query_for_list_of_conversions for CONVERSION in
words_after_create
Both patches are rebased on current master. All psql tests pass.
Thanks,
Shubh Mehta
On Fri, Dec 04, 2026 03:02 PM, Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp> wrote:
> > 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.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
>
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-psql-Add-tab-completion-for-dO-dc-and-det.patch | text/x-patch | 4.5 KB |
| v2-0002-psql-Keep-schema-name-when-completing-DROP-CONVER.patch | text/x-patch | 1.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Michael Banck | 2026-12-06 16:09:25 | Re: reltuples kept decreasing with each autovacuum run Re: BUG #18773 |