Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9ac00e

Browse files
committed
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, 3b17efd - 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.
1 parent b69f2e3 commit c9ac00e

File tree

5 files changed

+63
-27
lines changed

5 files changed

+63
-27
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ testdb=>
954954

955955

956956
<varlistentry>
957-
<term><literal>\dc[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
957+
<term><literal>\dc[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
958958
<listitem>
959959
<para>
960960
Lists conversions between character-set encodings.
@@ -964,6 +964,8 @@ testdb=&gt;
964964
By default, only user-created objects are shown; supply a
965965
pattern or the <literal>S</literal> modifier to include system
966966
objects.
967+
If <literal>+</literal> is appended to the command name, each object
968+
is listed with its associated description.
967969
</para>
968970
</listitem>
969971
</varlistentry>
@@ -977,6 +979,8 @@ testdb=&gt;
977979
If <replaceable class="parameter">pattern</replaceable>
978980
is specified, only casts whose source or target types match the
979981
pattern are listed.
982+
If <literal>+</literal> is appended to the command name, each object
983+
is listed with its associated description.
980984
</para>
981985
</listitem>
982986
</varlistentry>
@@ -1038,7 +1042,7 @@ testdb=&gt;
10381042

10391043

10401044
<varlistentry>
1041-
<term><literal>\dD[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1045+
<term><literal>\dD[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
10421046
<listitem>
10431047
<para>
10441048
Lists domains. If <replaceable
@@ -1047,6 +1051,8 @@ testdb=&gt;
10471051
By default, only user-created objects are shown; supply a
10481052
pattern or the <literal>S</literal> modifier to include system
10491053
objects.
1054+
If <literal>+</literal> is appended to the command name, each object
1055+
is listed with its associated description.
10501056
</para>
10511057
</listitem>
10521058
</varlistentry>

src/bin/psql/command.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ exec_command(const char *cmd,
378378
success = describeTablespaces(pattern, show_verbose);
379379
break;
380380
case 'c':
381-
success = listConversions(pattern, show_system);
381+
success = listConversions(pattern, show_verbose, show_system);
382382
break;
383383
case 'C':
384384
success = listCasts(pattern, show_verbose);
@@ -390,7 +390,7 @@ exec_command(const char *cmd,
390390
success = objectDescription(pattern, show_system);
391391
break;
392392
case 'D':
393-
success = listDomains(pattern, show_system);
393+
success = listDomains(pattern, show_verbose, show_system);
394394
break;
395395
case 'f': /* function subsystem */
396396
switch (cmd[2])

src/bin/psql/describe.c

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,10 +2665,8 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
26652665
gettext_noop("Owner"));
26662666

26672667
appendPQExpBuffer(&buf,
2668-
" l.lanpltrusted AS \"%s\",\n"
2669-
" d.description AS \"%s\"",
2670-
gettext_noop("Trusted"),
2671-
gettext_noop("Description"));
2668+
" l.lanpltrusted AS \"%s\"",
2669+
gettext_noop("Trusted"));
26722670

26732671
if (verbose)
26742672
{
@@ -2686,10 +2684,12 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
26862684
}
26872685

26882686
appendPQExpBuffer(&buf,
2687+
",\n d.description AS \"%s\""
26892688
"\nFROM pg_catalog.pg_language l\n"
26902689
"LEFT JOIN pg_catalog.pg_description d\n"
26912690
" ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
2692-
" AND d.objsubid = 0\n");
2691+
" AND d.objsubid = 0\n",
2692+
gettext_noop("Description"));
26932693

26942694
if (pattern)
26952695
processSQLNamePattern(pset.db, &buf, pattern, false, false,
@@ -2723,7 +2723,7 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
27232723
* Describes domains.
27242724
*/
27252725
bool
2726-
listDomains(const char *pattern, bool showSystem)
2726+
listDomains(const char *pattern, bool verbose, bool showSystem)
27272727
{
27282728
PQExpBufferData buf;
27292729
PGresult *res;
@@ -2746,17 +2746,30 @@ listDomains(const char *pattern, bool showSystem)
27462746
appendPQExpBuffer(&buf,
27472747
" CASE WHEN t.typnotnull THEN ' not null' ELSE '' END ||\n"
27482748
" CASE WHEN t.typdefault IS NOT NULL THEN ' default ' || t.typdefault ELSE '' END\n"
2749-
" ) as \"%s\",\n",
2750-
gettext_noop("Modifier"));
2751-
appendPQExpBuffer(&buf,
2749+
" ) as \"%s\",\n"
27522750
" pg_catalog.array_to_string(ARRAY(\n"
27532751
" SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
2754-
" ), ' ') as \"%s\"\n"
2755-
"FROM pg_catalog.pg_type t\n"
2756-
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
2757-
"WHERE t.typtype = 'd'\n",
2752+
" ), ' ') as \"%s\"",
2753+
gettext_noop("Modifier"),
27582754
gettext_noop("Check"));
27592755

2756+
if (verbose)
2757+
appendPQExpBuffer(&buf,
2758+
",\n d.description as \"%s\"",
2759+
gettext_noop("Description"));
2760+
2761+
appendPQExpBuffer(&buf,
2762+
"\nFROM pg_catalog.pg_type t\n"
2763+
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
2764+
2765+
if (verbose)
2766+
appendPQExpBuffer(&buf,
2767+
" LEFT JOIN pg_catalog.pg_description d "
2768+
"ON d.classoid = t.tableoid AND d.objoid = t.oid "
2769+
"AND d.objsubid = 0\n");
2770+
2771+
appendPQExpBuffer(&buf, "WHERE t.typtype = 'd'\n");
2772+
27602773
if (!showSystem && !pattern)
27612774
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
27622775
" AND n.nspname <> 'information_schema'\n");
@@ -2788,7 +2801,7 @@ listDomains(const char *pattern, bool showSystem)
27882801
* Describes conversions.
27892802
*/
27902803
bool
2791-
listConversions(const char *pattern, bool showSystem)
2804+
listConversions(const char *pattern, bool verbose, bool showSystem)
27922805
{
27932806
PQExpBufferData buf;
27942807
PGresult *res;
@@ -2803,19 +2816,36 @@ listConversions(const char *pattern, bool showSystem)
28032816
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
28042817
" pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
28052818
" CASE WHEN c.condefault THEN '%s'\n"
2806-
" ELSE '%s' END AS \"%s\"\n"
2807-
"FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
2808-
"WHERE n.oid = c.connamespace\n",
2819+
" ELSE '%s' END AS \"%s\"",
28092820
gettext_noop("Schema"),
28102821
gettext_noop("Name"),
28112822
gettext_noop("Source"),
28122823
gettext_noop("Destination"),
28132824
gettext_noop("yes"), gettext_noop("no"),
28142825
gettext_noop("Default?"));
28152826

2827+
if (verbose)
2828+
appendPQExpBuffer(&buf,
2829+
",\n d.description AS \"%s\"",
2830+
gettext_noop("Description"));
2831+
2832+
appendPQExpBuffer(&buf,
2833+
"\nFROM pg_catalog.pg_conversion c\n"
2834+
" JOIN pg_catalog.pg_namespace n "
2835+
"ON n.oid = c.connamespace\n");
2836+
2837+
if (verbose)
2838+
appendPQExpBuffer(&buf,
2839+
"LEFT JOIN pg_catalog.pg_description d "
2840+
"ON d.classoid = c.tableoid\n"
2841+
" AND d.objoid = c.oid "
2842+
"AND d.objsubid = 0\n");
2843+
2844+
appendPQExpBuffer(&buf, "WHERE true\n");
2845+
28162846
if (!showSystem && !pattern)
2817-
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
2818-
" AND n.nspname <> 'information_schema'\n");
2847+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
2848+
" AND n.nspname <> 'information_schema'\n");
28192849

28202850
processSQLNamePattern(pset.db, &buf, pattern, true, false,
28212851
"n.nspname", "c.conname", NULL,

src/bin/psql/describe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ extern bool listAllDbs(bool verbose);
6161
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem);
6262

6363
/* \dD */
64-
extern bool listDomains(const char *pattern, bool showSystem);
64+
extern bool listDomains(const char *pattern, bool verbose, bool showSystem);
6565

6666
/* \dc */
67-
extern bool listConversions(const char *pattern, bool showSystem);
67+
extern bool listConversions(const char *pattern, bool verbose, bool showSystem);
6868

6969
/* \dC */
7070
extern bool listCasts(const char *pattern, bool verbose);

src/bin/psql/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ slashUsage(unsigned short int pager)
195195
fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n"));
196196
fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
197197
fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
198-
fprintf(output, _(" \\dc[S] [PATTERN] list conversions\n"));
198+
fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n"));
199199
fprintf(output, _(" \\dC[+] [PATTERN] list casts\n"));
200200
fprintf(output, _(" \\dd[S] [PATTERN] show comments on objects\n"));
201201
fprintf(output, _(" \\ddp [PATTERN] list default privileges\n"));
202-
fprintf(output, _(" \\dD[S] [PATTERN] list domains\n"));
202+
fprintf(output, _(" \\dD[S+] [PATTERN] list domains\n"));
203203
fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n"));
204204
fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
205205
fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n"));

0 commit comments

Comments
 (0)