Re: psql: tab completion offers invalid COPY option values

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: psql: tab completion offers invalid COPY option values
Date: 2026-10-30 06:51:51
Message-ID: 97717993-E37D-4891-A467-7E7B87B10C60@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 30, 2026, at 12:40, Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com> wrote:
>
> Hi,
>
> While browsing the code, found that tab completion for two COPY option values does not take the COPY direction into account, so it offers values the server rejects.
>
> 1. COPY ... FROM ... WITH (FORMAT <TAB> offers json, but COPY FROM does not support it:
>
> =# copy t from '/dev/null' with (format json);
> ERROR: COPY FORMAT JSON is not supported for COPY FROM
>
> 2. COPY ... TO ... WITH (HEADER <TAB> offers MATCH, but it is valid only for COPY FROM:
>
> =# copy t to '/dev/null' with (header match);
> ERROR: cannot use "match" with HEADER in COPY TO
>

Good catch.

> The option-name completion already distinguishes the two directions, using Copy_from_options and Copy_to_options selected by HeadMatches("COPY|\\copy", MatchAny, "FROM"). The value completions for FORMAT and HEADER sit in the same block.
>
> The attached patch applies that same HeadMatches check to the FORMAT and HEADER rules.
>
> --
>
> Thanks & Regards,
> Suraj kharage,
>
>
>
> enterprisedb.com
> <v1-0001-psql-Fix-tab-completion-of-COPY-FORMAT-and-HEADER.patch>

V1 looks good to me. And I tested it locally, it works for me as expected.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-10-30 06:54:34 Re: Fix error handling in pg_flush_data() and FilePrefetch()
Previous Message solai v 2026-10-30 06:46:45 Re: Enable partitionwise join for partition keys wrapped by RelabelType