Commit c9ac00e6 authored by Robert Haas's avatar Robert Haas

Teach psql to display the comments on conversions and domains.

\dc and \dD now accept a "+" option, which will cause the comments to
be displayed.  Along the way, correct a few oversights in the previous
commit in this area, 3b17efdf - namely,
(1) when \dL+ is used, make description still be the last column, for
consistency with what we've done elsewhere; and (2) document the
difference between \dC and \dC+.

Josh Kupershmidt, with a couple of doc changes by me.
parent b69f2e36
...@@ -954,7 +954,7 @@ testdb=> ...@@ -954,7 +954,7 @@ testdb=>
<varlistentry> <varlistentry>
<term><literal>\dc[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term> <term><literal>\dc[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem> <listitem>
<para> <para>
Lists conversions between character-set encodings. Lists conversions between character-set encodings.
...@@ -964,6 +964,8 @@ testdb=&gt; ...@@ -964,6 +964,8 @@ testdb=&gt;
By default, only user-created objects are shown; supply a By default, only user-created objects are shown; supply a
pattern or the <literal>S</literal> modifier to include system pattern or the <literal>S</literal> modifier to include system
objects. objects.
If <literal>+</literal> is appended to the command name, each object
is listed with its associated description.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -977,6 +979,8 @@ testdb=&gt; ...@@ -977,6 +979,8 @@ testdb=&gt;
If <replaceable class="parameter">pattern</replaceable> If <replaceable class="parameter">pattern</replaceable>
is specified, only casts whose source or target types match the is specified, only casts whose source or target types match the
pattern are listed. pattern are listed.
If <literal>+</literal> is appended to the command name, each object
is listed with its associated description.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1038,7 +1042,7 @@ testdb=&gt; ...@@ -1038,7 +1042,7 @@ testdb=&gt;
<varlistentry> <varlistentry>
<term><literal>\dD[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term> <term><literal>\dD[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem> <listitem>
<para> <para>
Lists domains. If <replaceable Lists domains. If <replaceable
...@@ -1047,6 +1051,8 @@ testdb=&gt; ...@@ -1047,6 +1051,8 @@ testdb=&gt;
By default, only user-created objects are shown; supply a By default, only user-created objects are shown; supply a
pattern or the <literal>S</literal> modifier to include system pattern or the <literal>S</literal> modifier to include system
objects. objects.
If <literal>+</literal> is appended to the command name, each object
is listed with its associated description.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -378,7 +378,7 @@ exec_command(const char *cmd, ...@@ -378,7 +378,7 @@ exec_command(const char *cmd,
success = describeTablespaces(pattern, show_verbose); success = describeTablespaces(pattern, show_verbose);
break; break;
case 'c': case 'c':
success = listConversions(pattern, show_system); success = listConversions(pattern, show_verbose, show_system);
break; break;
case 'C': case 'C':
success = listCasts(pattern, show_verbose); success = listCasts(pattern, show_verbose);
...@@ -390,7 +390,7 @@ exec_command(const char *cmd, ...@@ -390,7 +390,7 @@ exec_command(const char *cmd,
success = objectDescription(pattern, show_system); success = objectDescription(pattern, show_system);
break; break;
case 'D': case 'D':
success = listDomains(pattern, show_system); success = listDomains(pattern, show_verbose, show_system);
break; break;
case 'f': /* function subsystem */ case 'f': /* function subsystem */
switch (cmd[2]) switch (cmd[2])
......
...@@ -2665,10 +2665,8 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) ...@@ -2665,10 +2665,8 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
gettext_noop("Owner")); gettext_noop("Owner"));
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
" l.lanpltrusted AS \"%s\",\n" " l.lanpltrusted AS \"%s\"",
" d.description AS \"%s\"", gettext_noop("Trusted"));
gettext_noop("Trusted"),
gettext_noop("Description"));
if (verbose) if (verbose)
{ {
...@@ -2686,10 +2684,12 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) ...@@ -2686,10 +2684,12 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
} }
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n d.description AS \"%s\""
"\nFROM pg_catalog.pg_language l\n" "\nFROM pg_catalog.pg_language l\n"
"LEFT JOIN pg_catalog.pg_description d\n" "LEFT JOIN pg_catalog.pg_description d\n"
" ON d.classoid = l.tableoid AND d.objoid = l.oid\n" " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
" AND d.objsubid = 0\n"); " AND d.objsubid = 0\n",
gettext_noop("Description"));
if (pattern) if (pattern)
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
...@@ -2723,7 +2723,7 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) ...@@ -2723,7 +2723,7 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
* Describes domains. * Describes domains.
*/ */
bool bool
listDomains(const char *pattern, bool showSystem) listDomains(const char *pattern, bool verbose, bool showSystem)
{ {
PQExpBufferData buf; PQExpBufferData buf;
PGresult *res; PGresult *res;
...@@ -2746,17 +2746,30 @@ listDomains(const char *pattern, bool showSystem) ...@@ -2746,17 +2746,30 @@ listDomains(const char *pattern, bool showSystem)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
" CASE WHEN t.typnotnull THEN ' not null' ELSE '' END ||\n" " CASE WHEN t.typnotnull THEN ' not null' ELSE '' END ||\n"
" CASE WHEN t.typdefault IS NOT NULL THEN ' default ' || t.typdefault ELSE '' END\n" " CASE WHEN t.typdefault IS NOT NULL THEN ' default ' || t.typdefault ELSE '' END\n"
" ) as \"%s\",\n", " ) as \"%s\",\n"
gettext_noop("Modifier"));
appendPQExpBuffer(&buf,
" pg_catalog.array_to_string(ARRAY(\n" " pg_catalog.array_to_string(ARRAY(\n"
" SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n" " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
" ), ' ') as \"%s\"\n" " ), ' ') as \"%s\"",
"FROM pg_catalog.pg_type t\n" gettext_noop("Modifier"),
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
"WHERE t.typtype = 'd'\n",
gettext_noop("Check")); gettext_noop("Check"));
if (verbose)
appendPQExpBuffer(&buf,
",\n d.description as \"%s\"",
gettext_noop("Description"));
appendPQExpBuffer(&buf,
"\nFROM pg_catalog.pg_type t\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
if (verbose)
appendPQExpBuffer(&buf,
" LEFT JOIN pg_catalog.pg_description d "
"ON d.classoid = t.tableoid AND d.objoid = t.oid "
"AND d.objsubid = 0\n");
appendPQExpBuffer(&buf, "WHERE t.typtype = 'd'\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
...@@ -2788,7 +2801,7 @@ listDomains(const char *pattern, bool showSystem) ...@@ -2788,7 +2801,7 @@ listDomains(const char *pattern, bool showSystem)
* Describes conversions. * Describes conversions.
*/ */
bool bool
listConversions(const char *pattern, bool showSystem) listConversions(const char *pattern, bool verbose, bool showSystem)
{ {
PQExpBufferData buf; PQExpBufferData buf;
PGresult *res; PGresult *res;
...@@ -2803,9 +2816,7 @@ listConversions(const char *pattern, bool showSystem) ...@@ -2803,9 +2816,7 @@ listConversions(const char *pattern, bool showSystem)
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n" " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
" pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n" " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
" CASE WHEN c.condefault THEN '%s'\n" " CASE WHEN c.condefault THEN '%s'\n"
" ELSE '%s' END AS \"%s\"\n" " ELSE '%s' END AS \"%s\"",
"FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
"WHERE n.oid = c.connamespace\n",
gettext_noop("Schema"), gettext_noop("Schema"),
gettext_noop("Name"), gettext_noop("Name"),
gettext_noop("Source"), gettext_noop("Source"),
...@@ -2813,6 +2824,25 @@ listConversions(const char *pattern, bool showSystem) ...@@ -2813,6 +2824,25 @@ listConversions(const char *pattern, bool showSystem)
gettext_noop("yes"), gettext_noop("no"), gettext_noop("yes"), gettext_noop("no"),
gettext_noop("Default?")); gettext_noop("Default?"));
if (verbose)
appendPQExpBuffer(&buf,
",\n d.description AS \"%s\"",
gettext_noop("Description"));
appendPQExpBuffer(&buf,
"\nFROM pg_catalog.pg_conversion c\n"
" JOIN pg_catalog.pg_namespace n "
"ON n.oid = c.connamespace\n");
if (verbose)
appendPQExpBuffer(&buf,
"LEFT JOIN pg_catalog.pg_description d "
"ON d.classoid = c.tableoid\n"
" AND d.objoid = c.oid "
"AND d.objsubid = 0\n");
appendPQExpBuffer(&buf, "WHERE true\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
......
...@@ -61,10 +61,10 @@ extern bool listAllDbs(bool verbose); ...@@ -61,10 +61,10 @@ extern bool listAllDbs(bool verbose);
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);
/* \dD */ /* \dD */
extern bool listDomains(const char *pattern, bool showSystem); extern bool listDomains(const char *pattern, bool verbose, bool showSystem);
/* \dc */ /* \dc */
extern bool listConversions(const char *pattern, bool showSystem); extern bool listConversions(const char *pattern, bool verbose, bool showSystem);
/* \dC */ /* \dC */
extern bool listCasts(const char *pattern, bool verbose); extern bool listCasts(const char *pattern, bool verbose);
......
...@@ -195,11 +195,11 @@ slashUsage(unsigned short int pager) ...@@ -195,11 +195,11 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n")); fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n"));
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"));
fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n")); fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n"));
fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n")); fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n")); fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\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