| From: | Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> |
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> |
| Cc: | Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM |
| Date: | 2025-12-22 17:22:53 |
| Message-ID: | 20251223022253.55847ef3833317d4a8bb6092@sraoss.co.jp |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, 23 Dec 2025 00:37:05 +0900
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
> On Mon, 24 Nov 2025 15:32:36 -0800
> Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> I'm sorry for the late response.
>
> > Thank you for updating the patch! I have one question about the
> > following change:
> >
> > + /* Complete COPY <sth> FROM|TO [PROGRAM] filename WITH ( */
> > + else if (HeadMatches("COPY|\\copy", MatchAny, "FROM|TO",
> > MatchAnyExcept("PROGRAM"), "WITH", "(") ||
> > + HeadMatches("COPY|\\copy", MatchAny, "FROM|TO",
> > "PROGRAM", MatchAny, "WITH", "("))
> > + {
> > + if (!HeadMatches("COPY|\\copy", MatchAny, "FROM|TO",
> > MatchAnyExcept("PROGRAM"), "WITH", "(*)") &&
> > + !HeadMatches("COPY|\\copy", MatchAny, "FROM|TO",
> > "PROGRAM", MatchAny, "WITH", "(*)"))
> > + {
> >
> > Given get_previous_words() treats a completed parenthesized option
> > list as one word, why is the later if statement necessary? In the
> > situation where the condition of the later if statement becomes false,
> > the condition of the first 'else if' statement should have become
> > false, no?
>
> First of all, the condition of the outer 'else if' was wrong.
> What I actually meant was:
>
> + /* Complete COPY <sth> FROM|TO [PROGRAM] filename WITH ( */
> + else if (HeadMatches("COPY|\\copy", MatchAny, "FROM|TO",
> MatchAnyExcept("PROGRAM"), "WITH", "(*") ||
> + HeadMatches("COPY|\\copy", MatchAny, "FROM|TO",
> "PROGRAM", MatchAny, "WITH", "(*"))
>
> That is, the last word should be "(*" instead of "(".
> I've attached an updated patch reflecting this fix.
>
> This patterm is mimic how option lists are handled in the other places.
> For example:
>
> 3160 else if (HeadMatches("ANALYZE", "(*") &&
> 3161 !HeadMatches("ANALYZE", "(*)"))
>
> This prevents option completion after a completed paranthesized option list.
> For example, after "ANALYZE (VERVOSE ON) tbl (", no ANALYZE options are suggested,
> instead column names of the table "tbl" are suggested.
>
> Similarly, this change prevents completion of COPY options after
> "COPY tbl FROM stdin WITH ( FORMAT text ) WHERE (", for example.
By the way, while investigating your comments, I noticed an issue with
tab completion for VACUUM option values. I reported it in a separate
thread [1], since it appears to be a bug introduced by another commit.
[1] https://www.postgresql.org/message-id/20251223021509.19bba68ecbbc70c9f983c2b4%40sraoss.co.jp
--
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2025-12-22 17:26:42 | Two issues with version checks in CREATE SUBSCRIPTION |
| Previous Message | Yugo Nagata | 2025-12-22 17:15:09 | psql: Fix tab completion for VACUUM option values |