v1-0001-psql-make-P-prompt-escape-consistent-when-not-con.patch

application/octet-stream

Filename: v1-0001-psql-make-P-prompt-escape-consistent-when-not-con.patch
Type: application/octet-stream
Part: 0
Message: psql: make %P prompt option consistent when not connected

Patch

Format: format-patch
Series: patch v1-0001
Subject: psql: make %P prompt escape consistent when not connected
File+
src/bin/psql/prompt.c 2 2
From 0fa5336d5da7ec7ff2b0dd087a3aac6644979ab9 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 28 Jan 2026 16:19:47 +0800
Subject: [PATCH v1] psql: make %P prompt escape consistent when not connected

The %P prompt escape shows the current pipeline status.  Unlike most
other prompt escapes, it was evaluated even when psql was not connected
to a database.

Make %P behave consistently with the other prompt options by only
expanding it when a database connection exists.  This keeps the prompt
display consistent in the not-connected state.

Author: Chao Li <lic@highgo.com>
Reviewed-by:
Discussion:
---
 src/bin/psql/prompt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 44eae59641e..891cd6374f0 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -199,6 +199,7 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
 					break;
 					/* pipeline status */
 				case 'P':
+					if (pset.db)
 					{
 						PGpipelineStatus status = PQpipelineStatus(pset.db);
 
@@ -208,9 +209,8 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
 							strlcpy(buf, "abort", sizeof(buf));
 						else
 							strlcpy(buf, "off", sizeof(buf));
-						break;
 					}
-
+					break;
 				case '0':
 				case '1':
 				case '2':
-- 
2.50.1 (Apple Git-155)