[PATCH v1] psql: Do not complete JSON format for COPY FROM

Started by Koshino Taikiabout 20 hours ago4 messageshackers
Jump to latest
#1Koshino Taiki
koshino@sraoss.co.jp

Hi,

I noticed that psql's tab completion suggests the JSON format for both
directions of COPY.

For example:

COPY t1 FROM STDIN WITH (FORMAT <TAB><TAB>
binary csv json text

However, the documentation says that the JSON format is allowed only
for COPY TO. If a user selects the suggested "json" candidate, the
command fails:

COPY t1 FROM STDIN WITH (FORMAT JSON);
ERROR: COPY FORMAT JSON is not supported for COPY FROM

I think it is misleading for tab completion to suggest syntax that is
explicitly unsupported by the documentation and rejected by the
server.

The attached patch checks the COPY direction and offers "json" only
for COPY TO. This applies to both COPY and \copy completion.

There is already a separate discussion proposing support for COPY FROM
with FORMAT json [1]/messages/by-id/CAEG8a3+wxMXGLcnrDzSF0qTDzH+K7_x0FWNAcu-H_j8gKiwFVw@mail.gmail.com. If that support is committed, the completion can
of course be extended at the same time. However, in the current tree
COPY FROM does not support JSON, so I think tab completion should
reflect the currently implemented and documented behavior.

[1]: /messages/by-id/CAEG8a3+wxMXGLcnrDzSF0qTDzH+K7_x0FWNAcu-H_j8gKiwFVw@mail.gmail.com
/messages/by-id/CAEG8a3+wxMXGLcnrDzSF0qTDzH+K7_x0FWNAcu-H_j8gKiwFVw@mail.gmail.com

Regards,

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

Attachments:

t254544_1
v1-0001-psql-Do-not-complete-JSON-format-for-COPY-FROM.patchapplication/octet-stream; name=v1-0001-psql-Do-not-complete-JSON-format-for-COPY-FROM.patchDownload+6-2
#2Sho Ito
i.sho.0628@gmail.com
In reply to: Koshino Taiki (#1)
Re: [PATCH v1] psql: Do not complete JSON format for COPY FROM

On Tue, Nov 3, 2026 at 8:23 PM Koshino Taiki <koshino@sraoss.co.jp> wrote:

The attached patch checks the COPY direction and offers "json" only
for COPY TO. This applies to both COPY and \copy completion.

Hi Taiki,

I reviewed v1 on master with assertions enabled. The build and before/after
Readline completion checks pass. Console checks confirm that both `COPY`
and `\copy` reject `FORMAT JSON` for `FROM` and accept it for `TO`, matching
the backend logic [1]https://github.com/postgres/postgres/blob/126976a8ffcfa47f40d3df09243ebf4606001912/src/backend/commands/copy.c#L994-L998. The patch looks correct to me.

[1]: https://github.com/postgres/postgres/blob/126976a8ffcfa47f40d3df09243ebf4606001912/src/backend/commands/copy.c#L994-L998
https://github.com/postgres/postgres/blob/126976a8ffcfa47f40d3df09243ebf4606001912/src/backend/commands/copy.c#L994-L998

Thanks,
Sho

--
=======================================
*Sho Ito (Sean)*

E-mail: i.sho.0628@gmail.com
LinkedIn: *https://www.linkedin.com/in/sho-ito-0628/
<https://www.linkedin.com/in/sho-ito-0628/>*
GitHub: https://github.com/sean0628/
=======================================

#3Chao Li
li.evan.chao@gmail.com
In reply to: Koshino Taiki (#1)
Re: [PATCH v1] psql: Do not complete JSON format for COPY FROM

On Nov 4, 2026, at 09:22, Koshino Taiki <koshino@sraoss.co.jp> wrote:

Hi,

I noticed that psql's tab completion suggests the JSON format for both
directions of COPY.

For example:

COPY t1 FROM STDIN WITH (FORMAT <TAB><TAB>
binary csv json text

However, the documentation says that the JSON format is allowed only
for COPY TO. If a user selects the suggested "json" candidate, the
command fails:

COPY t1 FROM STDIN WITH (FORMAT JSON);
ERROR: COPY FORMAT JSON is not supported for COPY FROM

I think it is misleading for tab completion to suggest syntax that is
explicitly unsupported by the documentation and rejected by the
server.

The attached patch checks the COPY direction and offers "json" only
for COPY TO. This applies to both COPY and \copy completion.

There is already a separate discussion proposing support for COPY FROM
with FORMAT json [1]. If that support is committed, the completion can
of course be extended at the same time. However, in the current tree
COPY FROM does not support JSON, so I think tab completion should
reflect the currently implemented and documented behavior.

[1]
/messages/by-id/CAEG8a3+wxMXGLcnrDzSF0qTDzH+K7_x0FWNAcu-H_j8gKiwFVw@mail.gmail.com

Regards,

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

<v1-0001-psql-Do-not-complete-JSON-format-for-COPY-FROM.patch>

Same as the other your patch, the fix looks good, however, there is an earlier patch [1]/messages/by-id/CAF1DzPXjeGHhpgKzEWmpuoxdZWwErN79yRodOkwRYAt7Bdn2BA@mail.gmail.com already.

[1]: /messages/by-id/CAF1DzPXjeGHhpgKzEWmpuoxdZWwErN79yRodOkwRYAt7Bdn2BA@mail.gmail.com

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

#4Koshino Taiki
koshino@sraoss.co.jp
In reply to: Chao Li (#3)
Re: [PATCH v1] psql: Do not complete JSON format for COPY FROM

Same as the other your patch, the fix looks good, however, there is an earlier patch [1] already.

[1] /messages/by-id/CAF1DzPXjeGHhpgKzEWmpuoxdZWwErN79yRodOkwRYAt7Bdn2BA@mail.gmail.com

Hi,

As pointed out, the same issues have already been addressed
in an
earlier patch, so I am withdrawing my patches.

Regards,

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

________________________________
差出人: Chao Li <li.evan.chao@gmail.com>
送信日時: 2026年11月4日 16:08
宛先: Koshino Taiki <koshino@sraoss.co.jp>
CC: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Yugo Nagata <nagata@sraoss.co.jp>
件名: Re: [PATCH v1] psql: Do not complete JSON format for COPY FROM

On Nov 4, 2026, at 09:22, Koshino Taiki <koshino@sraoss.co.jp> wrote:

Hi,

I noticed that psql's tab completion suggests the JSON format for both
directions of COPY.

For example:

COPY t1 FROM STDIN WITH (FORMAT <TAB><TAB>
binary csv json text

However, the documentation says that the JSON format is allowed only
for COPY TO. If a user selects the suggested "json" candidate, the
command fails:

COPY t1 FROM STDIN WITH (FORMAT JSON);
ERROR: COPY FORMAT JSON is not supported for COPY FROM

I think it is misleading for tab completion to suggest syntax that is
explicitly unsupported by the documentation and rejected by the
server.

The attached patch checks the COPY direction and offers "json" only
for COPY TO. This applies to both COPY and \copy completion.

There is already a separate discussion proposing support for COPY FROM
with FORMAT json [1]. If that support is committed, the completion can
of course be extended at the same time. However, in the current tree
COPY FROM does not support JSON, so I think tab completion should
reflect the currently implemented and documented behavior.

[1]
/messages/by-id/CAEG8a3+wxMXGLcnrDzSF0qTDzH+K7_x0FWNAcu-H_j8gKiwFVw@mail.gmail.com

Regards,

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

<v1-0001-psql-Do-not-complete-JSON-format-for-COPY-FROM.patch>

Same as the other your patch, the fix looks good, however, there is an earlier patch [1]/messages/by-id/CAF1DzPXjeGHhpgKzEWmpuoxdZWwErN79yRodOkwRYAt7Bdn2BA@mail.gmail.com already.

[1]: /messages/by-id/CAF1DzPXjeGHhpgKzEWmpuoxdZWwErN79yRodOkwRYAt7Bdn2BA@mail.gmail.com

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