summaryrefslogtreecommitdiff
path: root/src/bin/psql/prompt.c
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2025-10-28 14:08:38 -0500
committerNathan Bossart <nathan@postgresql.org>2025-10-28 14:08:38 -0500
commitb3ce55f413cdf70b1bc4724052fb4eacf9de239a (patch)
treec7ad69826884e46abefcace15d06add4ee30e302 /src/bin/psql/prompt.c
parent03fbb0814c5015ab79e670ab97bb6a3349269e4b (diff)
Add psql PROMPT variable for search_path.
The new %S substitution shows the current value of 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. On older versions that don't report search_path, %S is replaced with a question mark. Suggested-by: Lauri Siltanen <lauri.siltanen@gmail.com> Author: Florents Tselai <florents.tselai@gmail.com> Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl> Reviewed-by: Jim Jones <jim.jones@uni-muenster.de> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/CANsM767JhTKCRagTaq5Lz52fVwLPVkhSpyD1C%2BOrridGv0SO0A%40mail.gmail.com
Diffstat (limited to 'src/bin/psql/prompt.c')
-rw-r--r--src/bin/psql/prompt.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index b08d7328fbf..59a2ceee07a 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");
+
+ /* Use ? for versions that don't report search_path. */
+ strlcpy(buf, sp ? sp : "?", sizeof(buf));
+ }
+ break;
/* service name */
case 's':
{