From 23fb2c1e2b857464f4e71c4227f716b195891cc9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 27 Oct 2025 15:12:29 -0500 Subject: [PATCH v4 1/1] Add psql PROMPT variable for the current search_path. The new %S substitution shows the current search_path. Note that this only works when connected to Postgres v18 or newer, since search_path was first marked as GUC_REPORT in commit 28a1121fd9. Suggested-by: Lauri Siltanen Author: Florents Tselai Reviewed-by: Jelte Fennema-Nio Reviewed-by: Jim Jones Reviewed-by: Chao Li Discussion: https://postgr.es/m/CANsM767JhTKCRagTaq5Lz52fVwLPVkhSpyD1C%2BOrridGv0SO0A%40mail.gmail.com --- doc/src/sgml/ref/psql-ref.sgml | 7 +++++++ src/bin/psql/prompt.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 1a339600bc4..d684c59a617 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -4974,6 +4974,13 @@ testdb=> INSERT INTO my_table VALUES (:'content'); + + %S + + The current . + + + %s The name of the service. diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index b08d7328fbf..b0a98f7e559 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -34,6 +34,7 @@ * %P - pipeline status: on, off or abort * %> - database server port number * %n - database user name + * %S - search_path * %s - service * %/ - current database * %~ - like %/ but "~" when database name equals user name @@ -167,6 +168,16 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) if (pset.db) strlcpy(buf, session_username(), sizeof(buf)); break; + /* search_path */ + case 'S': + if (pset.db) + { + const char *sp = PQparameterStatus(pset.db, "search_path"); + + if (sp) + strlcpy(buf, sp, sizeof(buf)); + } + break; /* service name */ case 's': { -- 2.39.5 (Apple Git-154)