Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit477728b

Browse files
committed
psql: Add more information about service name
This commit adds support for the following items in psql, able to show aservice name, when available:- Variable SERVICE.- Substitution %s in PROMPT{1,2,3}.This relies on4b99fed, that has made the service name available inPGconn for libpq.Author: Michael BanckReviewed-by: Greg Sabino MullaneDiscussion:https://postgr.es/m/6723c612.050a0220.1567f4.b94a@mx.google.com
1 parent4b99fed commit477728b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4380,6 +4380,15 @@ bar
43804380
</listitem>
43814381
</varlistentry>
43824382

4383+
<varlistentry id="app-psql-variables-service">
4384+
<term><varname>SERVICE</varname></term>
4385+
<listitem>
4386+
<para>
4387+
The service name, if applicable.
4388+
</para>
4389+
</listitem>
4390+
</varlistentry>
4391+
43834392
<varlistentry id="app-psql-variables-shell-error">
43844393
<term><varname>SHELL_ERROR</varname></term>
43854394
<listitem>
@@ -4674,6 +4683,11 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
46744683
</listitem>
46754684
</varlistentry>
46764685

4686+
<varlistentry id="app-psql-prompting-s">
4687+
<term><literal>%s</literal></term>
4688+
<listitem><para>The name of the service.</para></listitem>
4689+
</varlistentry>
4690+
46774691
<varlistentry id="app-psql-prompting-slash">
46784692
<term><literal>%/</literal></term>
46794693
<listitem><para>The name of the current database.</para></listitem>

‎src/bin/psql/command.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,7 @@ SyncVariables(void)
40824082
pset.sversion=PQserverVersion(pset.db);
40834083

40844084
SetVariable(pset.vars,"DBNAME",PQdb(pset.db));
4085+
SetVariable(pset.vars,"SERVICE",PQservice(pset.db));
40854086
SetVariable(pset.vars,"USER",PQuser(pset.db));
40864087
SetVariable(pset.vars,"HOST",PQhost(pset.db));
40874088
SetVariable(pset.vars,"PORT",PQport(pset.db));
@@ -4115,6 +4116,7 @@ void
41154116
UnsyncVariables(void)
41164117
{
41174118
SetVariable(pset.vars,"DBNAME",NULL);
4119+
SetVariable(pset.vars,"SERVICE",NULL);
41184120
SetVariable(pset.vars,"USER",NULL);
41194121
SetVariable(pset.vars,"HOST",NULL);
41204122
SetVariable(pset.vars,"PORT",NULL);

‎src/bin/psql/prompt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* %p - backend pid
3434
* %> - database server port number
3535
* %n - database user name
36+
* %s - service
3637
* %/ - current database
3738
* %~ - like %/ but "~" when database name equals user name
3839
* %w - whitespace of the same width as the most recent output of PROMPT1
@@ -165,6 +166,11 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
165166
if (pset.db)
166167
strlcpy(buf,session_username(),sizeof(buf));
167168
break;
169+
/* service name */
170+
case's':
171+
if (pset.db&&PQservice(pset.db))
172+
strlcpy(buf,PQservice(pset.db),sizeof(buf));
173+
break;
168174
/* backend pid */
169175
case'p':
170176
if (pset.db)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp