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

Commit0ea1f6e

Browse files
peteremhagander
authored andcommitted
psql: Let \l accept a pattern
reviewed by Satoshi Nagayasu
1 parent54d6706 commit0ea1f6e

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,12 +1745,13 @@ hello 10
17451745

17461746

17471747
<varlistentry>
1748-
<term><literal>\l</literal> (or <literal>\list</literal>)</term>
1749-
<term><literal>\l+</literal> (or <literal>\list+</literal>)</term>
1748+
<term><literal>\l[+]</literal> or <literal>\list[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
17501749
<listitem>
17511750
<para>
1752-
List the names, owners, character set encodings, and access privileges
1753-
of all the databases in the server.
1751+
List the databases in the server and show their names, owners,
1752+
character set encodings, and access privileges.
1753+
If <replaceable class="parameter">pattern</replaceable> is specified,
1754+
only databases whose names match the pattern are listed.
17541755
If <literal>+</literal> is appended to the command name, database
17551756
sizes, default tablespaces, and descriptions are also displayed.
17561757
(Size information is only available for databases that the current

‎src/bin/psql/command.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,22 @@ exec_command(const char *cmd,
821821
}
822822

823823
/* \l is list databases */
824-
elseif (strcmp(cmd,"l")==0||strcmp(cmd,"list")==0)
825-
success=listAllDbs(false);
826-
elseif (strcmp(cmd,"l+")==0||strcmp(cmd,"list+")==0)
827-
success=listAllDbs(true);
824+
elseif (strcmp(cmd,"l")==0||strcmp(cmd,"list")==0||
825+
strcmp(cmd,"l+")==0||strcmp(cmd,"list+")==0)
826+
{
827+
char*pattern;
828+
boolshow_verbose;
829+
830+
pattern=psql_scan_slash_option(scan_state,
831+
OT_NORMAL,NULL, true);
832+
833+
show_verbose=strchr(cmd,'+') ? true : false;
834+
835+
success=listAllDbs(pattern,show_verbose);
836+
837+
if (pattern)
838+
free(pattern);
839+
}
828840

829841
/*
830842
* large object things

‎src/bin/psql/describe.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ describeOperators(const char *pattern, bool showSystem)
641641
* for \l, \list, and -l switch
642642
*/
643643
bool
644-
listAllDbs(boolverbose)
644+
listAllDbs(constchar*pattern,boolverbose)
645645
{
646646
PGresult*res;
647647
PQExpBufferDatabuf;
@@ -684,6 +684,11 @@ listAllDbs(bool verbose)
684684
if (verbose&&pset.sversion >=80000)
685685
appendPQExpBuffer(&buf,
686686
" JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
687+
688+
if (pattern)
689+
processSQLNamePattern(pset.db,&buf,pattern, false, false,
690+
NULL,"d.datname",NULL,NULL);
691+
687692
appendPQExpBuffer(&buf,"ORDER BY 1;");
688693
res=PSQLexec(buf.data, false);
689694
termPQExpBuffer(&buf);

‎src/bin/psql/describe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern bool listTSDictionaries(const char *pattern, bool verbose);
5555
externboollistTSTemplates(constchar*pattern,boolverbose);
5656

5757
/* \l */
58-
externboollistAllDbs(boolverbose);
58+
externboollistAllDbs(constchar*pattern,boolverbose);
5959

6060
/* \dt, \di, \ds, \dS, etc. */
6161
externboollistTables(constchar*tabtypes,constchar*pattern,boolverbose,boolshowSystem);

‎src/bin/psql/help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ slashUsage(unsigned short int pager)
235235
fprintf(output,_(" \\dE[S+] [PATTERN] list foreign tables\n"));
236236
fprintf(output,_(" \\dx[+] [PATTERN] list extensions\n"));
237237
fprintf(output,_(" \\dy [PATTERN] list event triggers\n"));
238-
fprintf(output,_(" \\l[+]list all databases\n"));
238+
fprintf(output,_(" \\l[+][PATTERN] list databases\n"));
239239
fprintf(output,_(" \\sf[+] FUNCNAME show a function's definition\n"));
240240
fprintf(output,_(" \\z [PATTERN] same as \\dp\n"));
241241
fprintf(output,"\n");

‎src/bin/psql/startup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ main(int argc, char *argv[])
260260
if (!options.no_psqlrc)
261261
process_psqlrc(argv[0]);
262262

263-
success=listAllDbs(false);
263+
success=listAllDbs(NULL,false);
264264
PQfinish(pset.db);
265265
exit(success ?EXIT_SUCCESS :EXIT_FAILURE);
266266
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp