diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2013-03-03 22:17:08 -0500 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2013-03-04 15:17:40 +0000 |
commit | 0ea1f6e98fc84f1c5f66cc6355f6e20582295e81 (patch) | |
tree | 6add782d94206a65350ff6ecd97579dfc64baedf /src | |
parent | 54d6706ded5c612a7f9b16eb6ddb08f44e24bb70 (diff) | |
download | postgresql-0ea1f6e98fc84f1c5f66cc6355f6e20582295e81.tar.gz |
psql: Let \l accept a pattern
reviewed by Satoshi Nagayasu
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/command.c | 20 | ||||
-rw-r--r-- | src/bin/psql/describe.c | 7 | ||||
-rw-r--r-- | src/bin/psql/describe.h | 2 | ||||
-rw-r--r-- | src/bin/psql/help.c | 2 | ||||
-rw-r--r-- | src/bin/psql/startup.c | 2 |
5 files changed, 25 insertions, 8 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 3be7c442a4..c33f9446b2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -821,10 +821,22 @@ exec_command(const char *cmd, } /* \l is list databases */ - else if (strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0) - success = listAllDbs(false); - else if (strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0) - success = listAllDbs(true); + else if (strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0 || + strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0) + { + 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 diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 217c3f5a3a..4ce831a433 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -641,7 +641,7 @@ describeOperators(const char *pattern, bool showSystem) * for \l, \list, and -l switch */ bool -listAllDbs(bool verbose) +listAllDbs(const char *pattern, bool verbose) { PGresult *res; PQExpBufferData buf; @@ -684,6 +684,11 @@ listAllDbs(bool verbose) if (verbose && pset.sversion >= 80000) appendPQExpBuffer(&buf, " 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;"); res = PSQLexec(buf.data, false); termPQExpBuffer(&buf); diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index 9e71a887c1..09b623751d 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -55,7 +55,7 @@ extern bool listTSDictionaries(const char *pattern, bool verbose); extern bool listTSTemplates(const char *pattern, bool verbose); /* \l */ -extern bool listAllDbs(bool verbose); +extern bool listAllDbs(const char *pattern, bool verbose); /* \dt, \di, \ds, \dS, etc. */ extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem); diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 819a20f18d..ccb307b791 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -235,7 +235,7 @@ slashUsage(unsigned short int pager) fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n")); fprintf(output, _(" \\dx[+] [PATTERN] list extensions\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, _(" \\z [PATTERN] same as \\dp\n")); fprintf(output, "\n"); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index a59f45b8a7..5cb6b5f364 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -260,7 +260,7 @@ main(int argc, char *argv[]) if (!options.no_psqlrc) process_psqlrc(argv[0]); - success = listAllDbs(false); + success = listAllDbs(NULL, false); PQfinish(pset.db); exit(success ? EXIT_SUCCESS : EXIT_FAILURE); } |