Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b17efd

Browse files
committed
Teach psql to display comments on languages and casts.
The output of \dL (list languages) is fairly narrow, so we just alwaysdisplay the comment. \dC (list casts) can get fairly wide, so we onlydisplay comments if the new \dC+ option is specified.Josh Kupershmidt
1 parent38de5aa commit3b17efd

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ testdb=>
966966

967967

968968
<varlistentry>
969-
<term><literal>\dC [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
969+
<term><literal>\dC[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
970970
<listitem>
971971
<para>
972972
Lists type casts.

‎src/bin/psql/command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ exec_command(const char *cmd,
381381
success=listConversions(pattern,show_system);
382382
break;
383383
case'C':
384-
success=listCasts(pattern);
384+
success=listCasts(pattern,show_verbose);
385385
break;
386386
case'd':
387387
if (strncmp(cmd,"ddp",3)==0)

‎src/bin/psql/describe.c

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,8 +2647,10 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
26472647
gettext_noop("Owner"));
26482648

26492649
appendPQExpBuffer(&buf,
2650-
" l.lanpltrusted AS \"%s\"",
2651-
gettext_noop("Trusted"));
2650+
" l.lanpltrusted AS \"%s\",\n"
2651+
" d.description AS \"%s\"",
2652+
gettext_noop("Trusted"),
2653+
gettext_noop("Description"));
26522654

26532655
if (verbose)
26542656
{
@@ -2666,13 +2668,18 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
26662668
}
26672669

26682670
appendPQExpBuffer(&buf,
2669-
"\nFROM pg_catalog.pg_language l\n");
2671+
"\nFROM pg_catalog.pg_language l\n"
2672+
"LEFT JOIN pg_catalog.pg_description d\n"
2673+
" ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
2674+
" AND d.objsubid = 0\n");
26702675

2671-
processSQLNamePattern(pset.db,&buf,pattern, false, false,
2672-
NULL,"l.lanname",NULL,NULL);
2676+
if (pattern)
2677+
processSQLNamePattern(pset.db,&buf,pattern, false, false,
2678+
NULL,"l.lanname",NULL,NULL);
26732679

26742680
if (!showSystem&& !pattern)
2675-
appendPQExpBuffer(&buf,"WHERE lanplcallfoid != 0\n");
2681+
appendPQExpBuffer(&buf,"WHERE l.lanplcallfoid != 0\n");
2682+
26762683

26772684
appendPQExpBuffer(&buf,"ORDER BY 1;");
26782685

@@ -2820,7 +2827,7 @@ listConversions(const char *pattern, bool showSystem)
28202827
* Describes casts.
28212828
*/
28222829
bool
2823-
listCasts(constchar*pattern)
2830+
listCasts(constchar*pattern,boolverbose)
28242831
{
28252832
PQExpBufferDatabuf;
28262833
PGresult*res;
@@ -2844,7 +2851,21 @@ listCasts(const char *pattern)
28442851
" CASE WHEN c.castcontext = 'e' THEN '%s'\n"
28452852
" WHEN c.castcontext = 'a' THEN '%s'\n"
28462853
" ELSE '%s'\n"
2847-
" END as \"%s\"\n"
2854+
" END as \"%s\"",
2855+
gettext_noop("Source type"),
2856+
gettext_noop("Target type"),
2857+
gettext_noop("Function"),
2858+
gettext_noop("no"),
2859+
gettext_noop("in assignment"),
2860+
gettext_noop("yes"),
2861+
gettext_noop("Implicit?"));
2862+
2863+
if (verbose)
2864+
appendPQExpBuffer(&buf,
2865+
",\n d.description AS \"%s\"\n",
2866+
gettext_noop("Description"));
2867+
2868+
appendPQExpBuffer(&buf,
28482869
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
28492870
" ON c.castfunc = p.oid\n"
28502871
" LEFT JOIN pg_catalog.pg_type ts\n"
@@ -2854,13 +2875,15 @@ listCasts(const char *pattern)
28542875
" LEFT JOIN pg_catalog.pg_type tt\n"
28552876
" ON c.casttarget = tt.oid\n"
28562877
" LEFT JOIN pg_catalog.pg_namespace nt\n"
2857-
" ON nt.oid = tt.typnamespace\n"
2858-
"WHERE (true",
2859-
gettext_noop("Source type"),
2860-
gettext_noop("Target type"),
2861-
gettext_noop("Function"),
2862-
gettext_noop("no"),gettext_noop("in assignment"),gettext_noop("yes"),
2863-
gettext_noop("Implicit?"));
2878+
" ON nt.oid = tt.typnamespace\n");
2879+
2880+
if (verbose)
2881+
appendPQExpBuffer(&buf,
2882+
" LEFT JOIN pg_catalog.pg_description d\n"
2883+
" ON d.classoid = c.tableoid AND d.objoid = "
2884+
"c.oid AND d.objsubid = 0\n");
2885+
2886+
appendPQExpBuffer(&buf,"WHERE ( (true");
28642887

28652888
/*
28662889
* Match name pattern against either internal or external name of either
@@ -2878,7 +2901,7 @@ listCasts(const char *pattern)
28782901
"pg_catalog.format_type(tt.oid, NULL)",
28792902
"pg_catalog.pg_type_is_visible(tt.oid)");
28802903

2881-
appendPQExpBuffer(&buf,")\nORDER BY 1, 2;");
2904+
appendPQExpBuffer(&buf,") )\nORDER BY 1, 2;");
28822905

28832906
res=PSQLexec(buf.data, false);
28842907
termPQExpBuffer(&buf);

‎src/bin/psql/describe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern bool listDomains(const char *pattern, bool showSystem);
6767
externboollistConversions(constchar*pattern,boolshowSystem);
6868

6969
/* \dC */
70-
externboollistCasts(constchar*pattern);
70+
externboollistCasts(constchar*pattern,boolverbose);
7171

7272
/* \dO */
7373
externboollistCollations(constchar*pattern,boolverbose,boolshowSystem);

‎src/bin/psql/help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ slashUsage(unsigned short int pager)
196196
fprintf(output,_(" \\da[S] [PATTERN] list aggregates\n"));
197197
fprintf(output,_(" \\db[+] [PATTERN] list tablespaces\n"));
198198
fprintf(output,_(" \\dc[S] [PATTERN] list conversions\n"));
199-
fprintf(output,_(" \\dC [PATTERN] list casts\n"));
199+
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"));
202202
fprintf(output,_(" \\dD[S] [PATTERN] list domains\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp