psql: tab completion offers invalid COPY option values

Поиск
Список
Период
Сортировка
Искать

psql: tab completion offers invalid COPY option values

От:
Suraj Kharage <suraj.kharage@enterprisedb.com>
Дата:
Вложения:
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

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, 

Re: psql: tab completion offers invalid COPY option values

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Oct 30, 2026, at 12:40, Suraj Kharage  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  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  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 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/






FAQ