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

Commitcdc197c

Browse files
committed
Improve psql's \dC command to take a pattern parameter. Casts are shown
if their source or target types match the pattern (using the same definitionof "match" as \dT does). Per recent discussion.
1 parent5ae2952 commitcdc197c

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.211 2008/09/0620:18:08 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.212 2008/11/0615:18:35 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -894,10 +894,13 @@ testdb=&gt;
894894

895895

896896
<varlistentry>
897-
<term><literal>\dC</literal></term>
897+
<term><literal>\dC [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
898898
<listitem>
899899
<para>
900900
Lists all available type casts.
901+
If <replaceable class="parameter">pattern</replaceable>
902+
is specified, only casts whose source or target types match the
903+
pattern are listed.
901904
</para>
902905
</listitem>
903906
</varlistentry>

‎src/bin/psql/describe.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
1010
*
11-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.186 2008/11/03 19:08:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.187 2008/11/06 15:18:35 tgl Exp $
1212
*/
1313
#include"postgres_fe.h"
1414

@@ -2082,10 +2082,10 @@ listCasts(const char *pattern)
20822082

20832083
initPQExpBuffer(&buf);
20842084
/*
2085-
* We need left joinherefor binary casts. Also note that we don't
2086-
*attempt to localize '(binary coercible)', because there's too much
2087-
*risk of gettext translating a function name that happens to match
2088-
* some string in the PO database.
2085+
* We needaleft jointo pg_procfor binary casts; the others are just
2086+
*paranoia. Also note that we don't attempt to localize '(binary
2087+
*coercible)', because there's too much risk of gettext translating a
2088+
*function name that happens to matchsome string in the PO database.
20892089
*/
20902090
printfPQExpBuffer(&buf,
20912091
"SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
@@ -2099,13 +2099,39 @@ listCasts(const char *pattern)
20992099
" END as \"%s\"\n"
21002100
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
21012101
" ON c.castfunc = p.oid\n"
2102-
"ORDER BY 1, 2",
2102+
" LEFT JOIN pg_catalog.pg_type ts\n"
2103+
" ON c.castsource = ts.oid\n"
2104+
" LEFT JOIN pg_catalog.pg_namespace ns\n"
2105+
" ON ns.oid = ts.typnamespace\n"
2106+
" LEFT JOIN pg_catalog.pg_type tt\n"
2107+
" ON c.casttarget = tt.oid\n"
2108+
" LEFT JOIN pg_catalog.pg_namespace nt\n"
2109+
" ON nt.oid = tt.typnamespace\n"
2110+
"WHERE (true",
21032111
gettext_noop("Source type"),
21042112
gettext_noop("Target type"),
21052113
gettext_noop("Function"),
21062114
gettext_noop("no"),gettext_noop("in assignment"),gettext_noop("yes"),
21072115
gettext_noop("Implicit?"));
21082116

2117+
/*
2118+
* Match name pattern against either internal or external name of either
2119+
* castsource or casttarget
2120+
*/
2121+
processSQLNamePattern(pset.db,&buf,pattern, true, false,
2122+
"ns.nspname","ts.typname",
2123+
"pg_catalog.format_type(ts.oid, NULL)",
2124+
"pg_catalog.pg_type_is_visible(ts.oid)");
2125+
2126+
appendPQExpBuffer(&buf,") OR (true");
2127+
2128+
processSQLNamePattern(pset.db,&buf,pattern, true, false,
2129+
"nt.nspname","tt.typname",
2130+
"pg_catalog.format_type(tt.oid, NULL)",
2131+
"pg_catalog.pg_type_is_visible(tt.oid)");
2132+
2133+
appendPQExpBuffer(&buf,")\nORDER BY 1, 2;");
2134+
21092135
res=PSQLexec(buf.data, false);
21102136
termPQExpBuffer(&buf);
21112137
if (!res)

‎src/bin/psql/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.130 2008/08/29 15:52:07 alvherre Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.131 2008/11/06 15:18:36 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -200,7 +200,7 @@ slashUsage(unsigned short int pager)
200200
fprintf(output,_(" \\da [PATTERN] list aggregate functions\n"));
201201
fprintf(output,_(" \\db [PATTERN] list tablespaces (add \"+\" for more detail)\n"));
202202
fprintf(output,_(" \\dc [PATTERN] list conversions\n"));
203-
fprintf(output,_(" \\dC list casts\n"));
203+
fprintf(output,_(" \\dC[PATTERN] list casts\n"));
204204
fprintf(output,_(" \\dd [PATTERN] show comment for object\n"));
205205
fprintf(output,_(" \\dD [PATTERN] list domains\n"));
206206
fprintf(output,_(" \\df [PATTERN] list functions (add \"+\" for more detail)\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp