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

Commitb4b62cf

Browse files
committed
Apply the proper version of Christopher Kings-Lynne's describe patch
(ie, the one with describe-schema support). Minor code review.Adjust display of casts to use standard type names.
1 parent1b59b44 commitb4b62cf

File tree

7 files changed

+125
-58
lines changed

7 files changed

+125
-58
lines changed

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

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.83 2003/01/0718:46:52 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.84 2003/01/0720:56:06 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -798,6 +798,30 @@ testdb=>
798798
</listitem>
799799
</varlistentry>
800800

801+
802+
<varlistentry>
803+
<term><literal>\dc</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
804+
<listitem>
805+
<para>
806+
Lists all available conversions between character-set encodings.
807+
If <replaceable class="parameter">pattern</replaceable>
808+
is specified, only conversions whose name matches the pattern are
809+
listed.
810+
</para>
811+
</listitem>
812+
</varlistentry>
813+
814+
815+
<varlistentry>
816+
<term><literal>\dC</literal></term>
817+
<listitem>
818+
<para>
819+
Lists all available type casts.
820+
</para>
821+
</listitem>
822+
</varlistentry>
823+
824+
801825
<varlistentry>
802826
<term><literal>\dd</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
803827
<listitem>
@@ -847,29 +871,6 @@ testdb=>
847871
</varlistentry>
848872

849873

850-
<varlistentry>
851-
<term><literal>\dc</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
852-
<listitem>
853-
<para>
854-
Lists all available conversions (between encodings). If <replaceable
855-
class="parameter">pattern</replaceable>
856-
is specified, only matching conversions are shown.
857-
</para>
858-
</listitem>
859-
</varlistentry>
860-
861-
862-
<varlistentry>
863-
<term><literal>\dC</literal></term>
864-
<listitem>
865-
<para>
866-
Lists all available type casts. Casts can be explicit, explicit and assignment
867-
or implicit, and are used to change a variable from one type to another.
868-
</para>
869-
</listitem>
870-
</varlistentry>
871-
872-
873874
<varlistentry>
874875
<term><literal>\df [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
875876

@@ -929,6 +930,19 @@ testdb=>
929930
</varlistentry>
930931

931932

933+
<varlistentry>
934+
<term><literal>\dn</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
935+
936+
<listitem>
937+
<para>
938+
Lists all available schemas (namespaces). If <replaceable
939+
class="parameter">pattern</replaceable> (a regular expression)
940+
is specified, only schemas whose name matches the pattern are listed.
941+
</para>
942+
</listitem>
943+
</varlistentry>
944+
945+
932946
<varlistentry>
933947
<term><literal>\do [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
934948
<listitem>
@@ -1054,8 +1068,9 @@ Tue Oct 26 21:40:57 CEST 1999
10541068
</para>
10551069
<note>
10561070
<para>
1057-
This command does not see changes made by <command>SET
1058-
CLIENT_ENCODING</>.
1071+
This command will not notice changes made directly by <command>SET
1072+
CLIENT_ENCODING</>. If you use <literal>\encoding</literal>,
1073+
be sure to use it to set as well as examine the encoding.
10591074
</para>
10601075
</note>
10611076
</listitem>

‎src/backend/catalog/namespace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.42 2002/12/12 21:02:19 momjian Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.43 2003/01/07 20:56:06 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -145,6 +145,7 @@ Datumpg_operator_is_visible(PG_FUNCTION_ARGS);
145145
Datumpg_opclass_is_visible(PG_FUNCTION_ARGS);
146146
Datumpg_conversion_is_visible(PG_FUNCTION_ARGS);
147147

148+
148149
/*
149150
* RangeVarGetRelid
150151
*Given a RangeVar describing an existing relation,
@@ -1084,7 +1085,7 @@ ConversionIsVisible(Oid conid)
10841085
ObjectIdGetDatum(conid),
10851086
0,0,0);
10861087
if (!HeapTupleIsValid(contup))
1087-
elog(ERROR,"Cache lookup failed forconverions %u",conid);
1088+
elog(ERROR,"Cache lookup failed forconversion %u",conid);
10881089
conform= (Form_pg_conversion)GETSTRUCT(contup);
10891090

10901091
recomputeNamespacePath();
@@ -1104,7 +1105,7 @@ ConversionIsVisible(Oid conid)
11041105
* If it is in the path, it might still not be visible; it could
11051106
* be hidden by another conversion of the same name earlier in the
11061107
* path. So we must do a slow check to see if this conversion would
1107-
* be found byConvnameGetConid.
1108+
* be found byConversionGetConid.
11081109
*/
11091110
char*conname=NameStr(conform->conname);
11101111

‎src/bin/psql/command.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.86 2002/12/12 21:02:21 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.87 2003/01/07 20:56:06 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -350,15 +350,27 @@ exec_command(const char *cmd,
350350
case'a':
351351
success=describeAggregates(pattern,show_verbose);
352352
break;
353+
case'c':
354+
success=listConversions(pattern);
355+
break;
356+
case'C':
357+
success=listCasts(pattern);
358+
break;
353359
case'd':
354360
success=objectDescription(pattern);
355361
break;
362+
case'D':
363+
success=listDomains(pattern);
364+
break;
356365
case'f':
357366
success=describeFunctions(pattern,show_verbose);
358367
break;
359368
case'l':
360369
success=do_lo_list();
361370
break;
371+
case'n':
372+
success=listSchemas(pattern);
373+
break;
362374
case'o':
363375
success=describeOperators(pattern);
364376
break;
@@ -378,16 +390,7 @@ exec_command(const char *cmd,
378390
case'u':
379391
success=describeUsers(pattern);
380392
break;
381-
case'D':
382-
success=listDomains(pattern);
383-
break;
384-
case'c':
385-
success=listConversions(pattern);
386-
break;
387-
case'C':
388-
success=listCasts(pattern);
389-
break;
390-
393+
391394
default:
392395
status=CMD_UNKNOWN;
393396
}

‎src/bin/psql/describe.c

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.73 2002/12/21 01:07:07 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.74 2003/01/07 20:56:06 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -1426,15 +1426,16 @@ listConversions(const char *pattern)
14261426
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
14271427
" pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
14281428
" CASE WHEN c.condefault THEN '%s'\n"
1429-
" ELSENULL END AS \"%s\"\n"
1429+
" ELSE'%s' END AS \"%s\"\n"
14301430
"FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
14311431
"WHERE n.oid = c.connamespace\n",
14321432
_("Schema"),
14331433
_("Name"),
14341434
_("Source"),
1435-
_("Dest"),
1436-
_("default"),
1437-
_("Modifier"));
1435+
_("Destination"),
1436+
_("yes"),
1437+
_("no"),
1438+
_("Default?"));
14381439

14391440
processNamePattern(&buf,pattern, true, false,
14401441
"n.nspname","c.conname",NULL,
@@ -1471,26 +1472,26 @@ listCasts(const char *pattern)
14711472
initPQExpBuffer(&buf);
14721473
/* NEED LEFT JOIN FOR BINARY CASTS */
14731474
printfPQExpBuffer(&buf,
1474-
"SELECTt1.typname AS \"%s\",\n"
1475-
"t2.typname AS \"%s\",\n"
1476-
" CASE WHENp.proname IS NULL THEN '%s'\n"
1475+
"SELECTpg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
1476+
"pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
1477+
" CASE WHENcastfunc = 0 THEN '%s'\n"
14771478
" ELSE p.proname\n"
14781479
" END as \"%s\",\n"
14791480
" CASE WHEN c.castcontext = 'e' THEN '%s'\n"
14801481
" WHEN c.castcontext = 'a' THEN '%s'\n"
14811482
" ELSE '%s'\n"
14821483
" END as \"%s\"\n"
14831484
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
1484-
"ON c.castfunc=p.oid, pg_catalog.pg_type t1, pg_catalog.pg_type t2\n"
1485-
"WHERE c.castsource=t1.oid AND c.casttarget=t2.oidORDER BY 1, 2",
1485+
" ON c.castfunc =p.oid\n"
1486+
"ORDER BY 1, 2",
14861487
_("Source"),
14871488
_("Target"),
14881489
_("BINARY"),
14891490
_("Function"),
1490-
_("explicit"),
1491-
_("assignment explicit"),
1492-
_("implicit"),
1493-
_("Context"));
1491+
_("no"),
1492+
_("in assignment"),
1493+
_("yes"),
1494+
_("Implicit?"));
14941495

14951496
res=PSQLexec(buf.data, false);
14961497
termPQExpBuffer(&buf);
@@ -1506,6 +1507,48 @@ listCasts(const char *pattern)
15061507
return true;
15071508
}
15081509

1510+
/*
1511+
* \dn
1512+
*
1513+
* Describes schemas (namespaces)
1514+
*/
1515+
bool
1516+
listSchemas(constchar*pattern)
1517+
{
1518+
PQExpBufferDatabuf;
1519+
PGresult*res;
1520+
printQueryOptmyopt=pset.popt;
1521+
1522+
initPQExpBuffer(&buf);
1523+
printfPQExpBuffer(&buf,
1524+
"SELECT n.nspname AS \"%s\",\n"
1525+
" u.usename AS \"%s\"\n"
1526+
"FROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_user u\n"
1527+
" ON n.nspowner=u.usesysid\n",
1528+
_("Name"),
1529+
_("Owner"));
1530+
1531+
processNamePattern(&buf,pattern, false, false,
1532+
NULL,"n.nspname",NULL,
1533+
NULL);
1534+
1535+
appendPQExpBuffer(&buf,"ORDER BY 1;");
1536+
1537+
res=PSQLexec(buf.data, false);
1538+
termPQExpBuffer(&buf);
1539+
if (!res)
1540+
return false;
1541+
1542+
myopt.nullPrint=NULL;
1543+
myopt.title=_("List of schemas");
1544+
1545+
printQuery(res,&myopt,pset.queryFout);
1546+
1547+
PQclear(res);
1548+
return true;
1549+
}
1550+
1551+
15091552
/*
15101553
* processNamePattern
15111554
*

‎src/bin/psql/describe.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.19 2002/12/12 21:02:24 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.20 2003/01/07 20:56:07 tgl Exp $
77
*/
88
#ifndefDESCRIBE_H
99
#defineDESCRIBE_H
@@ -49,5 +49,8 @@ boollistConversions(const char *pattern);
4949
/* \dC */
5050
boollistCasts(constchar*pattern);
5151

52+
/* \dn */
53+
boollistSchemas(constchar*pattern);
54+
5255

5356
#endif/* DESCRIBE_H */

‎src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.68 2002/12/13 22:17:57 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.69 2003/01/07 20:56:07 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -211,6 +211,7 @@ slashUsage(unsigned short int pager)
211211
fprintf(output,_(" \\dd [PATTERN] show comment for object\n"));
212212
fprintf(output,_(" \\dD [PATTERN] list domains\n"));
213213
fprintf(output,_(" \\df [PATTERN] list functions (add \"+\" for more detail)\n"));
214+
fprintf(output,_(" \\dn [PATTERN] list schemas\n"));
214215
fprintf(output,_(" \\do [NAME] list operators\n"));
215216
fprintf(output,_(" \\dl list large objects, same as \\lo_list\n"));
216217
fprintf(output,_(" \\dp [PATTERN] list table access privileges\n"));

‎src/include/catalog/namespace.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: namespace.h,v 1.23 2002/12/12 21:02:25 momjian Exp $
10+
* $Id: namespace.h,v 1.24 2003/01/07 20:56:07 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -65,8 +65,9 @@ extern bool OperatorIsVisible(Oid oprid);
6565
externOpclassCandidateListOpclassGetCandidates(Oidamid);
6666
externOidOpclassnameGetOpcid(Oidamid,constchar*opcname);
6767
externboolOpclassIsVisible(Oidopcid);
68-
externboolConversionIsVisible(Oidopcid);
68+
6969
externOidConversionGetConid(constchar*conname);
70+
externboolConversionIsVisible(Oidconid);
7071

7172
externvoidDeconstructQualifiedName(List*names,
7273
char**nspname_p,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp