]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
psql: Add tab completion for pstdin and pstdout in \copy.
authorMasahiko Sawada <msawada@postgresql.org>
Thu, 8 Jan 2026 00:22:42 +0000 (16:22 -0800)
committerMasahiko Sawada <msawada@postgresql.org>
Thu, 8 Jan 2026 00:22:42 +0000 (16:22 -0800)
This commit adds tab completion support for the keywords "pstdin" and
"pstdout" in the \copy command. "pstdin" is now suggested after FROM,
and "pstdout" is suggested after TO, alongside filenames and other
keywords.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/20251231183953.95132e171e43abd5e9b78084@sraoss.co.jp

src/bin/psql/tab-complete.in.c

index 06edea98f0608e1b6e84e4303b296408f2e7ab20..8b91bc000625a9bb5c6b3338a8d4407ba8086529 100644 (file)
@@ -3357,13 +3357,22 @@ match_previous_words(int pattern_id,
        /* Complete COPY|\copy <sth> FROM|TO with filename or STDIN/STDOUT/PROGRAM */
        else if (Matches("COPY|\\copy", MatchAny, "FROM|TO"))
        {
-               /* COPY requires quoted filename */
-               bool            force_quote = HeadMatches("COPY");
-
-               if (TailMatches("FROM"))
-                       COMPLETE_WITH_FILES_PLUS("", force_quote, "STDIN", "PROGRAM");
+               if (HeadMatches("COPY"))
+               {
+                       /* COPY requires quoted filename */
+                       if (TailMatches("FROM"))
+                               COMPLETE_WITH_FILES_PLUS("", true, "STDIN", "PROGRAM");
+                       else
+                               COMPLETE_WITH_FILES_PLUS("", true, "STDOUT", "PROGRAM");
+               }
                else
-                       COMPLETE_WITH_FILES_PLUS("", force_quote, "STDOUT", "PROGRAM");
+               {
+                       /* \copy supports pstdin and pstdout */
+                       if (TailMatches("FROM"))
+                               COMPLETE_WITH_FILES_PLUS("", false, "STDIN", "PSTDIN", "PROGRAM");
+                       else
+                               COMPLETE_WITH_FILES_PLUS("", false, "STDOUT", "PSTDOUT", "PROGRAM");
+               }
        }
 
        /* Complete COPY|\copy <sth> FROM|TO PROGRAM */