Commit 3b17efdf authored by Robert Haas's avatar Robert Haas

Teach psql to display comments on languages and casts.

The output of \dL (list languages) is fairly narrow, so we just always
display the comment.  \dC (list casts) can get fairly wide, so we only
display comments if the new \dC+ option is specified.

Josh Kupershmidt
parent 38de5aad
...@@ -966,7 +966,7 @@ testdb=> ...@@ -966,7 +966,7 @@ testdb=>
<varlistentry> <varlistentry>
<term><literal>\dC [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term> <term><literal>\dC[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem> <listitem>
<para> <para>
Lists type casts. Lists type casts.
......
...@@ -381,7 +381,7 @@ exec_command(const char *cmd, ...@@ -381,7 +381,7 @@ exec_command(const char *cmd,
success = listConversions(pattern, show_system); success = listConversions(pattern, show_system);
break; break;
case 'C': case 'C':
success = listCasts(pattern); success = listCasts(pattern, show_verbose);
break; break;
case 'd': case 'd':
if (strncmp(cmd, "ddp", 3) == 0) if (strncmp(cmd, "ddp", 3) == 0)
......
...@@ -2647,8 +2647,10 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) ...@@ -2647,8 +2647,10 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
gettext_noop("Owner")); gettext_noop("Owner"));
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
" l.lanpltrusted AS \"%s\"", " l.lanpltrusted AS \"%s\",\n"
gettext_noop("Trusted")); " d.description AS \"%s\"",
gettext_noop("Trusted"),
gettext_noop("Description"));
if (verbose) if (verbose)
{ {
...@@ -2666,13 +2668,18 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) ...@@ -2666,13 +2668,18 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
} }
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"\nFROM pg_catalog.pg_language l\n"); "\nFROM pg_catalog.pg_language l\n"
"LEFT JOIN pg_catalog.pg_description d\n"
" ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
" AND d.objsubid = 0\n");
processSQLNamePattern(pset.db, &buf, pattern, false, false, if (pattern)
NULL, "l.lanname", NULL, NULL); processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "l.lanname", NULL, NULL);
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, "WHERE lanplcallfoid != 0\n"); appendPQExpBuffer(&buf, "WHERE l.lanplcallfoid != 0\n");
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBuffer(&buf, "ORDER BY 1;");
...@@ -2820,7 +2827,7 @@ listConversions(const char *pattern, bool showSystem) ...@@ -2820,7 +2827,7 @@ listConversions(const char *pattern, bool showSystem)
* Describes casts. * Describes casts.
*/ */
bool bool
listCasts(const char *pattern) listCasts(const char *pattern, bool verbose)
{ {
PQExpBufferData buf; PQExpBufferData buf;
PGresult *res; PGresult *res;
...@@ -2844,7 +2851,21 @@ listCasts(const char *pattern) ...@@ -2844,7 +2851,21 @@ listCasts(const char *pattern)
" CASE WHEN c.castcontext = 'e' THEN '%s'\n" " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
" WHEN c.castcontext = 'a' THEN '%s'\n" " WHEN c.castcontext = 'a' THEN '%s'\n"
" ELSE '%s'\n" " ELSE '%s'\n"
" END as \"%s\"\n" " END as \"%s\"",
gettext_noop("Source type"),
gettext_noop("Target type"),
gettext_noop("Function"),
gettext_noop("no"),
gettext_noop("in assignment"),
gettext_noop("yes"),
gettext_noop("Implicit?"));
if (verbose)
appendPQExpBuffer(&buf,
",\n d.description AS \"%s\"\n",
gettext_noop("Description"));
appendPQExpBuffer(&buf,
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n" "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
" ON c.castfunc = p.oid\n" " ON c.castfunc = p.oid\n"
" LEFT JOIN pg_catalog.pg_type ts\n" " LEFT JOIN pg_catalog.pg_type ts\n"
...@@ -2854,13 +2875,15 @@ listCasts(const char *pattern) ...@@ -2854,13 +2875,15 @@ listCasts(const char *pattern)
" LEFT JOIN pg_catalog.pg_type tt\n" " LEFT JOIN pg_catalog.pg_type tt\n"
" ON c.casttarget = tt.oid\n" " ON c.casttarget = tt.oid\n"
" LEFT JOIN pg_catalog.pg_namespace nt\n" " LEFT JOIN pg_catalog.pg_namespace nt\n"
" ON nt.oid = tt.typnamespace\n" " ON nt.oid = tt.typnamespace\n");
"WHERE (true",
gettext_noop("Source type"), if (verbose)
gettext_noop("Target type"), appendPQExpBuffer(&buf,
gettext_noop("Function"), " LEFT JOIN pg_catalog.pg_description d\n"
gettext_noop("no"), gettext_noop("in assignment"), gettext_noop("yes"), " ON d.classoid = c.tableoid AND d.objoid = "
gettext_noop("Implicit?")); "c.oid AND d.objsubid = 0\n");
appendPQExpBuffer(&buf, "WHERE ( (true");
/* /*
* Match name pattern against either internal or external name of either * Match name pattern against either internal or external name of either
...@@ -2878,7 +2901,7 @@ listCasts(const char *pattern) ...@@ -2878,7 +2901,7 @@ listCasts(const char *pattern)
"pg_catalog.format_type(tt.oid, NULL)", "pg_catalog.format_type(tt.oid, NULL)",
"pg_catalog.pg_type_is_visible(tt.oid)"); "pg_catalog.pg_type_is_visible(tt.oid)");
appendPQExpBuffer(&buf, ")\nORDER BY 1, 2;"); appendPQExpBuffer(&buf, ") )\nORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
......
...@@ -67,7 +67,7 @@ extern bool listDomains(const char *pattern, bool showSystem); ...@@ -67,7 +67,7 @@ extern bool listDomains(const char *pattern, bool showSystem);
extern bool listConversions(const char *pattern, bool showSystem); extern bool listConversions(const char *pattern, bool showSystem);
/* \dC */ /* \dC */
extern bool listCasts(const char *pattern); extern bool listCasts(const char *pattern, bool verbose);
/* \dO */ /* \dO */
extern bool listCollations(const char *pattern, bool verbose, bool showSystem); extern bool listCollations(const char *pattern, bool verbose, bool showSystem);
......
...@@ -196,7 +196,7 @@ slashUsage(unsigned short int pager) ...@@ -196,7 +196,7 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n")); fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n")); fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
fprintf(output, _(" \\dc[S] [PATTERN] list conversions\n")); fprintf(output, _(" \\dc[S] [PATTERN] list conversions\n"));
fprintf(output, _(" \\dC [PATTERN] list casts\n")); fprintf(output, _(" \\dC[+] [PATTERN] list casts\n"));
fprintf(output, _(" \\dd[S] [PATTERN] show comments on objects\n")); fprintf(output, _(" \\dd[S] [PATTERN] show comments on objects\n"));
fprintf(output, _(" \\ddp [PATTERN] list default privileges\n")); fprintf(output, _(" \\ddp [PATTERN] list default privileges\n"));
fprintf(output, _(" \\dD[S] [PATTERN] list domains\n")); fprintf(output, _(" \\dD[S] [PATTERN] list domains\n"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment