mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
psql: Let \l accept a pattern
reviewed by Satoshi Nagayasu
This commit is contained in:
parent
54d6706ded
commit
0ea1f6e98f
@ -1745,12 +1745,13 @@ hello 10
|
|||||||
|
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>\l</literal> (or <literal>\list</literal>)</term>
|
<term><literal>\l[+]</literal> or <literal>\list[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
||||||
<term><literal>\l+</literal> (or <literal>\list+</literal>)</term>
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
List the names, owners, character set encodings, and access privileges
|
List the databases in the server and show their names, owners,
|
||||||
of all the databases in the server.
|
character set encodings, and access privileges.
|
||||||
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
||||||
|
only databases whose names match the pattern are listed.
|
||||||
If <literal>+</literal> is appended to the command name, database
|
If <literal>+</literal> is appended to the command name, database
|
||||||
sizes, default tablespaces, and descriptions are also displayed.
|
sizes, default tablespaces, and descriptions are also displayed.
|
||||||
(Size information is only available for databases that the current
|
(Size information is only available for databases that the current
|
||||||
|
@ -821,10 +821,22 @@ exec_command(const char *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* \l is list databases */
|
/* \l is list databases */
|
||||||
else if (strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0)
|
else if (strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0 ||
|
||||||
success = listAllDbs(false);
|
strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0)
|
||||||
else if (strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0)
|
{
|
||||||
success = listAllDbs(true);
|
char *pattern;
|
||||||
|
bool show_verbose;
|
||||||
|
|
||||||
|
pattern = psql_scan_slash_option(scan_state,
|
||||||
|
OT_NORMAL, NULL, true);
|
||||||
|
|
||||||
|
show_verbose = strchr(cmd, '+') ? true : false;
|
||||||
|
|
||||||
|
success = listAllDbs(pattern, show_verbose);
|
||||||
|
|
||||||
|
if (pattern)
|
||||||
|
free(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* large object things
|
* large object things
|
||||||
|
@ -641,7 +641,7 @@ describeOperators(const char *pattern, bool showSystem)
|
|||||||
* for \l, \list, and -l switch
|
* for \l, \list, and -l switch
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
listAllDbs(bool verbose)
|
listAllDbs(const char *pattern, bool verbose)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
PQExpBufferData buf;
|
PQExpBufferData buf;
|
||||||
@ -684,6 +684,11 @@ listAllDbs(bool verbose)
|
|||||||
if (verbose && pset.sversion >= 80000)
|
if (verbose && pset.sversion >= 80000)
|
||||||
appendPQExpBuffer(&buf,
|
appendPQExpBuffer(&buf,
|
||||||
" JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
|
" JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
|
||||||
|
|
||||||
|
if (pattern)
|
||||||
|
processSQLNamePattern(pset.db, &buf, pattern, false, false,
|
||||||
|
NULL, "d.datname", NULL, NULL);
|
||||||
|
|
||||||
appendPQExpBuffer(&buf, "ORDER BY 1;");
|
appendPQExpBuffer(&buf, "ORDER BY 1;");
|
||||||
res = PSQLexec(buf.data, false);
|
res = PSQLexec(buf.data, false);
|
||||||
termPQExpBuffer(&buf);
|
termPQExpBuffer(&buf);
|
||||||
|
@ -55,7 +55,7 @@ extern bool listTSDictionaries(const char *pattern, bool verbose);
|
|||||||
extern bool listTSTemplates(const char *pattern, bool verbose);
|
extern bool listTSTemplates(const char *pattern, bool verbose);
|
||||||
|
|
||||||
/* \l */
|
/* \l */
|
||||||
extern bool listAllDbs(bool verbose);
|
extern bool listAllDbs(const char *pattern, bool verbose);
|
||||||
|
|
||||||
/* \dt, \di, \ds, \dS, etc. */
|
/* \dt, \di, \ds, \dS, etc. */
|
||||||
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem);
|
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem);
|
||||||
|
@ -235,7 +235,7 @@ slashUsage(unsigned short int pager)
|
|||||||
fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n"));
|
fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n"));
|
||||||
fprintf(output, _(" \\dx[+] [PATTERN] list extensions\n"));
|
fprintf(output, _(" \\dx[+] [PATTERN] list extensions\n"));
|
||||||
fprintf(output, _(" \\dy [PATTERN] list event triggers\n"));
|
fprintf(output, _(" \\dy [PATTERN] list event triggers\n"));
|
||||||
fprintf(output, _(" \\l[+] list all databases\n"));
|
fprintf(output, _(" \\l[+] [PATTERN] list databases\n"));
|
||||||
fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n"));
|
fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n"));
|
||||||
fprintf(output, _(" \\z [PATTERN] same as \\dp\n"));
|
fprintf(output, _(" \\z [PATTERN] same as \\dp\n"));
|
||||||
fprintf(output, "\n");
|
fprintf(output, "\n");
|
||||||
|
@ -260,7 +260,7 @@ main(int argc, char *argv[])
|
|||||||
if (!options.no_psqlrc)
|
if (!options.no_psqlrc)
|
||||||
process_psqlrc(argv[0]);
|
process_psqlrc(argv[0]);
|
||||||
|
|
||||||
success = listAllDbs(false);
|
success = listAllDbs(NULL, false);
|
||||||
PQfinish(pset.db);
|
PQfinish(pset.db);
|
||||||
exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
|
exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user