Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM - Mailing list pgsql-hackers

From Yugo Nagata
Subject Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM
Date
Msg-id 20251223100217.ecaf852e3271138246b3e006@sraoss.co.jp
Whole thread Raw
In response to Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM  (Masahiko Sawada <sawada.mshk@gmail.com>)
List pgsql-hackers
On Mon, 22 Dec 2025 14:31:51 -0800
Masahiko Sawada <sawada.mshk@gmail.com> wrote:

> On Mon, Dec 22, 2025 at 7:37 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> >
> > On Mon, 24 Nov 2025 15:32:36 -0800
> > Masahiko Sawada <sawada.mshk@gmail.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.
> 
> Thank you for updating the patch and the explanation!
> 
> I agree with these changes, so I've pushed the patch. Also, this
> commit fest item is now marked as 'Committed'.

Thank you!

Regards,
Yugo Nagata

-- 
Yugo Nagata <nagata@sraoss.co.jp>



pgsql-hackers by date:

Previous
From: Paul A Jungwirth
Date:
Subject: Re: Postgres Patch Review Workshop: January 2026
Next
From: Melanie Plageman
Date:
Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)