summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml11
-rw-r--r--src/bin/psql/prompt.c11
2 files changed, 22 insertions, 0 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 1a339600bc4..84683f62b1c 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -4974,6 +4974,17 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
</listitem>
</varlistentry>
+ <varlistentry id="app-psql-prompting-S">
+ <term><literal>%S</literal></term>
+ <listitem>
+ <para>
+ The current value of <xref linkend="guc-search-path"/>, or
+ <literal>?</literal> if connected to a server running
+ <productname>PostgreSQL</productname> 17 or older.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="app-psql-prompting-s">
<term><literal>%s</literal></term>
<listitem><para>The name of the service.</para></listitem>
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':
{