Re: PSQL - improve tab completion for pub/sub options

From: Peter Smith <smithpb2250(at)gmail(dot)com>
To: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: PSQL - improve tab completion for pub/sub options
Date: 2026-07-29 07:01:45
Message-ID: CAHut+PuoFBsddDupGk4o1RWWqcL1SGjMdfvF-SjttkuLSm=66g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Kuroda-San

Thanks for your review comments!

On Tue, Jul 28, 2026 at 4:46 PM Hayato Kuroda (Fujitsu)
<kuroda(dot)hayato(at)fujitsu(dot)com> wrote:
...
> 01.
> ```
> --- a/src/bin/psql/tab-complete.in.c
> +++ b/src/bin/psql/tab-complete.in.c
> @@ -2341,9 +2341,20 @@ match_previous_words(int pattern_id,
> COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_schemas
> " AND nspname NOT LIKE E'pg\\\\_%%'",
> "CURRENT_SCHEMA");
> - /* ALTER PUBLICATION <name> SET ( */
> - else if (Matches("ALTER", "PUBLICATION", MatchAny, MatchAnyN, "SET", "("))
> - COMPLETE_WITH("publish", "publish_generated_columns", "publish_via_partition_root");
> + /* ALTER PUBLICATION <name> SET ( <opt> */
> + else if (HeadMatches("ALTER", "PUBLICATION", MatchAny, "SET", "("))
> + {
> + if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
> ```
>
> According to others, the else-if statement should be slightly changed like:
>
> ```
> else if (HeadMatches("ALTER", "PUBLICATION", MatchAny, "SET", "(*") &&
> !HeadMatches("ALTER", "PUBLICATION", MatchAny, "SET", "(*)"))
> ```

Done as suggested.

>
> 02.
> ```
> + COMPLETE_WITH("publish", "publish_generated_columns =",
> + "publish_via_partition_root");
> ```
>
> Let me confirm the policy here: the parameter "publish" won't be accepted alone,
> but " =" is not completed for it. Is there a reason?
>
> 03.
> ```
> COMPLETE_WITH("binary", "conflict_log_destination =",
> + "disable_on_error", "failover", "max_retention_duration",
> + "origin =", "password_required", "retain_dead_tuples",
> + "run_as_owner", "slot_name", "streaming =",
> + "synchronous_commit =", "two_phase",
> ```
>
> Same as 02. max_retention_duration and slot_name cannot be alone.
>

I initially included " =" only for the enum options. But you are
correct; it could/should have been added for some of the other options
too. Fixed now.

> 04.
>
> While testing, I recognized that the word "PUBLICATION" cannot be suggested
> if users input till below. Can you also fix?
>
> ```
> postgres=# CREATE SUBSCRIPTION sub CONNECTION 'dbname=tmp'
> ```

Hmm, I don't think you have to try very hard to find lots of examples
where tab-completion could be improved.

The scope of this particular thread/patch is *only* the pub/sub
options. I am happy to investigate what you reported, but that belongs
in another thread.

~~~

PSA patch v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

Attachment Content-Type Size
v2-0001-psql-tab-completion-of-pub-sub-options.patch application/octet-stream 8.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Chen 2026-07-29 07:12:37 Re: pg_plan_advice: add NO_ scan and join method tags
Previous Message vignesh C 2026-07-29 06:55:08 Re: sequencesync worker race with REFRESH SEQUENCES