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

Commitd913928

Browse files
committed
psql: Add support for \dpS and \zS.
This allows an optional "S" modifier to be added to \dp and \z, tohave them include system objects in the list.Note that this also changes the behaviour of a bare \dp or \z withoutthe "S" modifier to include temp objects in the list, and excludeinformation_schema objects, making them consistent with other psqlmeta-commands.Nathan Bossart, reviewed by Maxim Orlov.Discussion:https://postgr.es/m/20221206193606.GB3078082@nathanxps13
1 parent2b6df05 commitd913928

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,14 +1825,16 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
18251825

18261826

18271827
<varlistentry>
1828-
<term><literal>\dp [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1828+
<term><literal>\dp[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
18291829
<listitem>
18301830
<para>
18311831
Lists tables, views and sequences with their
18321832
associated access privileges.
18331833
If <replaceable class="parameter">pattern</replaceable> is
18341834
specified, only tables, views and sequences whose names match the
1835-
pattern are listed.
1835+
pattern are listed. By default only user-created objects are shown;
1836+
supply a pattern or the <literal>S</literal> modifier to include
1837+
system objects.
18361838
</para>
18371839

18381840
<para>
@@ -3575,14 +3577,16 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
35753577

35763578

35773579
<varlistentry>
3578-
<term><literal>\z [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
3580+
<term><literal>\z[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
35793581
<listitem>
35803582
<para>
35813583
Lists tables, views and sequences with their
35823584
associated access privileges.
35833585
If a <replaceable class="parameter">pattern</replaceable> is
35843586
specified, only tables, views and sequences whose names match the
3585-
pattern are listed.
3587+
pattern are listed. By default only user-created objects are shown;
3588+
supply a pattern or the <literal>S</literal> modifier to include
3589+
system objects.
35863590
</para>
35873591

35883592
<para>

‎src/bin/psql/command.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ static backslashResult exec_command_write(PsqlScanState scan_state, bool active_
140140
staticbackslashResultexec_command_watch(PsqlScanStatescan_state,boolactive_branch,
141141
PQExpBufferquery_buf,PQExpBufferprevious_buf);
142142
staticbackslashResultexec_command_x(PsqlScanStatescan_state,boolactive_branch);
143-
staticbackslashResultexec_command_z(PsqlScanStatescan_state,boolactive_branch);
143+
staticbackslashResultexec_command_z(PsqlScanStatescan_state,boolactive_branch,
144+
constchar*cmd);
144145
staticbackslashResultexec_command_shell_escape(PsqlScanStatescan_state,boolactive_branch);
145146
staticbackslashResultexec_command_slash_command_help(PsqlScanStatescan_state,boolactive_branch);
146147
staticchar*read_connect_arg(PsqlScanStatescan_state);
@@ -413,8 +414,8 @@ exec_command(const char *cmd,
413414
query_buf,previous_buf);
414415
elseif (strcmp(cmd,"x")==0)
415416
status=exec_command_x(scan_state,active_branch);
416-
elseif (strcmp(cmd,"z")==0)
417-
status=exec_command_z(scan_state,active_branch);
417+
elseif (strcmp(cmd,"z")==0||strcmp(cmd,"zS")==0)
418+
status=exec_command_z(scan_state,active_branch,cmd);
418419
elseif (strcmp(cmd,"!")==0)
419420
status=exec_command_shell_escape(scan_state,active_branch);
420421
elseif (strcmp(cmd,"?")==0)
@@ -875,7 +876,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
875876
success=listCollations(pattern,show_verbose,show_system);
876877
break;
877878
case'p':
878-
success=permissionsList(pattern);
879+
success=permissionsList(pattern,show_system);
879880
break;
880881
case'P':
881882
{
@@ -2822,16 +2823,22 @@ exec_command_x(PsqlScanState scan_state, bool active_branch)
28222823
* \z -- list table privileges (equivalent to \dp)
28232824
*/
28242825
staticbackslashResult
2825-
exec_command_z(PsqlScanStatescan_state,boolactive_branch)
2826+
exec_command_z(PsqlScanStatescan_state,boolactive_branch,constchar*cmd)
28262827
{
28272828
boolsuccess= true;
28282829

28292830
if (active_branch)
28302831
{
2831-
char*pattern=psql_scan_slash_option(scan_state,
2832-
OT_NORMAL,NULL, true);
2832+
char*pattern;
2833+
boolshow_system;
2834+
2835+
pattern=psql_scan_slash_option(scan_state,
2836+
OT_NORMAL,NULL, true);
2837+
2838+
show_system=strchr(cmd,'S') ? true : false;
2839+
2840+
success=permissionsList(pattern,show_system);
28332841

2834-
success=permissionsList(pattern);
28352842
free(pattern);
28362843
}
28372844
else

‎src/bin/psql/describe.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ listAllDbs(const char *pattern, bool verbose)
10021002
* \z (now also \dp -- perhaps more mnemonic)
10031003
*/
10041004
bool
1005-
permissionsList(constchar*pattern)
1005+
permissionsList(constchar*pattern,boolshowSystem)
10061006
{
10071007
PQExpBufferDatabuf;
10081008
PGresult*res;
@@ -1121,15 +1121,13 @@ permissionsList(const char *pattern)
11211121
CppAsString2(RELKIND_FOREIGN_TABLE)","
11221122
CppAsString2(RELKIND_PARTITIONED_TABLE)")\n");
11231123

1124-
/*
1125-
* Unless a schema pattern is specified, we suppress system and temp
1126-
* tables, since they normally aren't very interesting from a permissions
1127-
* point of view. You can see 'em by explicit request though, eg with \z
1128-
* pg_catalog.*
1129-
*/
1124+
if (!showSystem&& !pattern)
1125+
appendPQExpBufferStr(&buf," AND n.nspname <> 'pg_catalog'\n"
1126+
" AND n.nspname <> 'information_schema'\n");
1127+
11301128
if (!validateSQLNamePattern(&buf,pattern, true, false,
11311129
"n.nspname","c.relname",NULL,
1132-
"n.nspname !~ '^pg_' ANDpg_catalog.pg_table_is_visible(c.oid)",
1130+
"pg_catalog.pg_table_is_visible(c.oid)",
11331131
NULL,3))
11341132
gotoerror_return;
11351133

‎src/bin/psql/describe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern bool describeRoles(const char *pattern, bool verbose, bool showSystem);
3838
externboollistDbRoleSettings(constchar*pattern,constchar*pattern2);
3939

4040
/* \z (or \dp) */
41-
externboolpermissionsList(constchar*pattern);
41+
externboolpermissionsList(constchar*pattern,boolshowSystem);
4242

4343
/* \ddp */
4444
externboollistDefaultACLs(constchar*pattern);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp