From 6e7d6f2d87ab009c6f8b6798f753fbd05fecf522 Mon Sep 17 00:00:00 2001 From: Taiki Koshino Date: Mon, 2 Nov 2026 17:21:48 +0900 Subject: [PATCH v1] psql: Do not complete JSON format for COPY FROM JSON format is supported only for COPY TO, but tab completion offered "json" after FORMAT for both COPY directions. For example, psql previously produced: COPY t1 FROM STDIN WITH (FORMAT binary csv json text However, selecting json results in: COPY t1 FROM STDIN WITH (FORMAT JSON); ERROR: COPY FORMAT JSON is not supported for COPY FROM Check the COPY direction and offer "json" only for COPY TO. --- src/bin/psql/tab-complete.in.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index cab52f5ba08..d0e39f46cfa 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -3436,7 +3436,12 @@ match_previous_words(int pattern_id, /* Complete COPY FROM|TO filename WITH (FORMAT */ else if (TailMatches("FORMAT")) - COMPLETE_WITH("binary", "csv", "text", "json"); + { + if (HeadMatches("COPY|\\copy", MatchAny, "FROM")) + COMPLETE_WITH("binary", "csv", "text"); + else + COMPLETE_WITH("binary", "csv", "text", "json"); + } /* Complete COPY FROM|TO filename WITH (FREEZE */ else if (TailMatches("FREEZE")) -- 2.52.0