psql: Add tab completion for \copy pstdin and pstdout

Started by Yugo Nagata12 days ago5 messages
#1Yugo Nagata
nagata@sraoss.co.jp
1 attachment(s)

Hi,

Commit 02fd47db improved tab completion for COPY FROM and COPY TO by
suggesting STDIN and STDOUT. How about also adding suggestions for
pstdin and pstdout in the case of the \copy meta-command?

I've attached a simple patch to add this.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

0001-psql-Add-tab-completion-for-copy-pstdin-and-pstdout.patchtext/x-diff; name=0001-psql-Add-tab-completion-for-copy-pstdin-and-pstdout.patchDownload
From 736639b10963438471ae0ab8b0e4657bbc86c016 Mon Sep 17 00:00:00 2001
From: Yugo Nagata <nagata@sraoss.co.jp>
Date: Wed, 31 Dec 2025 18:27:46 +0900
Subject: [PATCH] psql: Add tab completion for \copy pstdin and pstdout

---
 src/bin/psql/tab-complete.in.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 75a101c6ab5..5edb9ad4d77 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -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 */
-- 
2.43.0

#2Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Yugo Nagata (#1)
Re: psql: Add tab completion for \copy pstdin and pstdout

On Wed, Dec 31, 2025 at 1:40 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

Commit 02fd47db improved tab completion for COPY FROM and COPY TO by
suggesting STDIN and STDOUT. How about also adding suggestions for
pstdin and pstdout in the case of the \copy meta-command?

I've attached a simple patch to add this.

+1

The patch is quite simple and looks good to me. I'll push it, barring
any objections.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#3Srinath Reddy Sadipiralla
srinath2133@gmail.com
In reply to: Masahiko Sawada (#2)
Re: psql: Add tab completion for \copy pstdin and pstdout

Hi,

On Wed, Jan 7, 2026 at 6:06 AM Masahiko Sawada <sawada.mshk@gmail.com>
wrote:

On Wed, Dec 31, 2025 at 1:40 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

Commit 02fd47db improved tab completion for COPY FROM and COPY TO by
suggesting STDIN and STDOUT. How about also adding suggestions for
pstdin and pstdout in the case of the \copy meta-command?

I've attached a simple patch to add this.

+1

The patch is quite simple and looks good to me. I'll push it, barring
any objections.

+1, I have reviewed it and LGTM.

--
Thanks,
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/

#4Kirill Reshke
reshkekirill@gmail.com
In reply to: Srinath Reddy Sadipiralla (#3)
Re: psql: Add tab completion for \copy pstdin and pstdout

On Wed, 7 Jan 2026 at 08:34, Srinath Reddy Sadipiralla
<srinath2133@gmail.com> wrote:

Hi,

On Wed, Jan 7, 2026 at 6:06 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:

On Wed, Dec 31, 2025 at 1:40 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

Commit 02fd47db improved tab completion for COPY FROM and COPY TO by
suggesting STDIN and STDOUT. How about also adding suggestions for
pstdin and pstdout in the case of the \copy meta-command?

I've attached a simple patch to add this.

+1

The patch is quite simple and looks good to me. I'll push it, barring
any objections.

+1, I have reviewed it and LGTM.

--
Thanks,
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/

Hi!
I changed CF entry [0]https://commitfest.postgresql.org/patch/6365/ and changed status to RFC.
Patch looks good.

[0]: https://commitfest.postgresql.org/patch/6365/

--
Best regards,
Kirill Reshke

#5Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Kirill Reshke (#4)
Re: psql: Add tab completion for \copy pstdin and pstdout

On Wed, Jan 7, 2026 at 3:17 AM Kirill Reshke <reshkekirill@gmail.com> wrote:

On Wed, 7 Jan 2026 at 08:34, Srinath Reddy Sadipiralla
<srinath2133@gmail.com> wrote:

Hi,

On Wed, Jan 7, 2026 at 6:06 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:

On Wed, Dec 31, 2025 at 1:40 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

Commit 02fd47db improved tab completion for COPY FROM and COPY TO by
suggesting STDIN and STDOUT. How about also adding suggestions for
pstdin and pstdout in the case of the \copy meta-command?

I've attached a simple patch to add this.

+1

The patch is quite simple and looks good to me. I'll push it, barring
any objections.

+1, I have reviewed it and LGTM.

--
Thanks,
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/

Hi!
I changed CF entry [0] and changed status to RFC.
Patch looks good.

Pushed. I've marked the entry as committed.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com