From b4b62cff9343404edcf144df41765eb899d448bc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 7 Jan 2003 20:56:07 +0000 Subject: [PATCH] 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. --- doc/src/sgml/ref/psql-ref.sgml | 67 +++++++++++++++++++------------ src/backend/catalog/namespace.c | 7 ++-- src/bin/psql/command.c | 25 +++++++----- src/bin/psql/describe.c | 71 ++++++++++++++++++++++++++------- src/bin/psql/describe.h | 5 ++- src/bin/psql/help.c | 3 +- src/include/catalog/namespace.h | 5 ++- 7 files changed, 125 insertions(+), 58 deletions(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 77da336696..677b4773b4 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1,5 +1,5 @@ @@ -798,6 +798,30 @@ testdb=> + + + \dc [ pattern ] + + + Lists all available conversions between character-set encodings. + If pattern + is specified, only conversions whose name matches the pattern are + listed. + + + + + + + \dC + + + Lists all available type casts. + + + + + \dd [ pattern ] @@ -847,29 +871,6 @@ testdb=> - - \dc [ pattern ] - - - Lists all available conversions (between encodings). If pattern - is specified, only matching conversions are shown. - - - - - - - \dC - - - Lists all available type casts. Casts can be explicit, explicit and assignment - or implicit, and are used to change a variable from one type to another. - - - - - \df [ pattern ] @@ -929,6 +930,19 @@ testdb=> + + \dn [ pattern ] + + + + Lists all available schemas (namespaces). If pattern (a regular expression) + is specified, only schemas whose name matches the pattern are listed. + + + + + \do [ pattern ] @@ -1054,8 +1068,9 @@ Tue Oct 26 21:40:57 CEST 1999 - This command does not see changes made by SET - CLIENT_ENCODING. + This command will not notice changes made directly by SET + CLIENT_ENCODING. If you use \encoding, + be sure to use it to set as well as examine the encoding. diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index fa0d20af30..0c571ca2a4 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -13,7 +13,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.42 2002/12/12 21:02:19 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.43 2003/01/07 20:56:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -145,6 +145,7 @@ Datum pg_operator_is_visible(PG_FUNCTION_ARGS); Datum pg_opclass_is_visible(PG_FUNCTION_ARGS); Datum pg_conversion_is_visible(PG_FUNCTION_ARGS); + /* * RangeVarGetRelid * Given a RangeVar describing an existing relation, @@ -1084,7 +1085,7 @@ ConversionIsVisible(Oid conid) ObjectIdGetDatum(conid), 0, 0, 0); if (!HeapTupleIsValid(contup)) - elog(ERROR, "Cache lookup failed for converions %u", conid); + elog(ERROR, "Cache lookup failed for conversion %u", conid); conform = (Form_pg_conversion) GETSTRUCT(contup); recomputeNamespacePath(); @@ -1104,7 +1105,7 @@ ConversionIsVisible(Oid conid) * If it is in the path, it might still not be visible; it could * be hidden by another conversion of the same name earlier in the * path. So we must do a slow check to see if this conversion would - * be found by ConvnameGetConid. + * be found by ConversionGetConid. */ char *conname = NameStr(conform->conname); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 06d3159856..419e44a632 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.86 2002/12/12 21:02:21 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.87 2003/01/07 20:56:06 tgl Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -350,15 +350,27 @@ exec_command(const char *cmd, case 'a': success = describeAggregates(pattern, show_verbose); break; + case 'c': + success = listConversions(pattern); + break; + case 'C': + success = listCasts(pattern); + break; case 'd': success = objectDescription(pattern); break; + case 'D': + success = listDomains(pattern); + break; case 'f': success = describeFunctions(pattern, show_verbose); break; case 'l': success = do_lo_list(); break; + case 'n': + success = listSchemas(pattern); + break; case 'o': success = describeOperators(pattern); break; @@ -378,16 +390,7 @@ exec_command(const char *cmd, case 'u': success = describeUsers(pattern); break; - case 'D': - success = listDomains(pattern); - break; - case 'c': - success = listConversions(pattern); - break; - case 'C': - success = listCasts(pattern); - break; - + default: status = CMD_UNKNOWN; } diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index d4f7e1eded..0614b63da8 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.73 2002/12/21 01:07:07 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.74 2003/01/07 20:56:06 tgl Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -1426,15 +1426,16 @@ listConversions(const char *pattern) " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n" " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n" " CASE WHEN c.condefault THEN '%s'\n" - " ELSE NULL END AS \"%s\"\n" + " ELSE '%s' END AS \"%s\"\n" "FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n" "WHERE n.oid = c.connamespace\n", _("Schema"), _("Name"), _("Source"), - _("Dest"), - _("default"), - _("Modifier")); + _("Destination"), + _("yes"), + _("no"), + _("Default?")); processNamePattern(&buf, pattern, true, false, "n.nspname", "c.conname", NULL, @@ -1471,9 +1472,9 @@ listCasts(const char *pattern) initPQExpBuffer(&buf); /* NEED LEFT JOIN FOR BINARY CASTS */ printfPQExpBuffer(&buf, - "SELECT t1.typname AS \"%s\",\n" - " t2.typname AS \"%s\",\n" - " CASE WHEN p.proname IS NULL THEN '%s'\n" + "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n" + " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n" + " CASE WHEN castfunc = 0 THEN '%s'\n" " ELSE p.proname\n" " END as \"%s\",\n" " CASE WHEN c.castcontext = 'e' THEN '%s'\n" @@ -1481,16 +1482,16 @@ listCasts(const char *pattern) " ELSE '%s'\n" " END as \"%s\"\n" "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n" - " ON c.castfunc=p.oid, pg_catalog.pg_type t1, pg_catalog.pg_type t2\n" - "WHERE c.castsource=t1.oid AND c.casttarget=t2.oid ORDER BY 1, 2", + " ON c.castfunc = p.oid\n" + "ORDER BY 1, 2", _("Source"), _("Target"), _("BINARY"), _("Function"), - _("explicit"), - _("assignment explicit"), - _("implicit"), - _("Context")); + _("no"), + _("in assignment"), + _("yes"), + _("Implicit?")); res = PSQLexec(buf.data, false); termPQExpBuffer(&buf); @@ -1506,6 +1507,48 @@ listCasts(const char *pattern) return true; } +/* + * \dn + * + * Describes schemas (namespaces) + */ +bool +listSchemas(const char *pattern) +{ + PQExpBufferData buf; + PGresult *res; + printQueryOpt myopt = pset.popt; + + initPQExpBuffer(&buf); + printfPQExpBuffer(&buf, + "SELECT n.nspname AS \"%s\",\n" + " u.usename AS \"%s\"\n" + "FROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_user u\n" + " ON n.nspowner=u.usesysid\n", + _("Name"), + _("Owner")); + + processNamePattern(&buf, pattern, false, false, + NULL, "n.nspname", NULL, + NULL); + + appendPQExpBuffer(&buf, "ORDER BY 1;"); + + res = PSQLexec(buf.data, false); + termPQExpBuffer(&buf); + if (!res) + return false; + + myopt.nullPrint = NULL; + myopt.title = _("List of schemas"); + + printQuery(res, &myopt, pset.queryFout); + + PQclear(res); + return true; +} + + /* * processNamePattern * diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index 6461b41d30..40a94b0efd 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.19 2002/12/12 21:02:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.20 2003/01/07 20:56:07 tgl Exp $ */ #ifndef DESCRIBE_H #define DESCRIBE_H @@ -49,5 +49,8 @@ bool listConversions(const char *pattern); /* \dC */ bool listCasts(const char *pattern); +/* \dn */ +bool listSchemas(const char *pattern); + #endif /* DESCRIBE_H */ diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index e921f1da4b..2dcf798d9d 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.68 2002/12/13 22:17:57 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.69 2003/01/07 20:56:07 tgl Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -211,6 +211,7 @@ slashUsage(unsigned short int pager) fprintf(output, _(" \\dd [PATTERN] show comment for object\n")); fprintf(output, _(" \\dD [PATTERN] list domains\n")); fprintf(output, _(" \\df [PATTERN] list functions (add \"+\" for more detail)\n")); + fprintf(output, _(" \\dn [PATTERN] list schemas\n")); fprintf(output, _(" \\do [NAME] list operators\n")); fprintf(output, _(" \\dl list large objects, same as \\lo_list\n")); fprintf(output, _(" \\dp [PATTERN] list table access privileges\n")); diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h index 27e3e75168..8bcd487670 100644 --- a/src/include/catalog/namespace.h +++ b/src/include/catalog/namespace.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: namespace.h,v 1.23 2002/12/12 21:02:25 momjian Exp $ + * $Id: namespace.h,v 1.24 2003/01/07 20:56:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -65,8 +65,9 @@ extern bool OperatorIsVisible(Oid oprid); extern OpclassCandidateList OpclassGetCandidates(Oid amid); extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname); extern bool OpclassIsVisible(Oid opcid); -extern bool ConversionIsVisible(Oid opcid); + extern Oid ConversionGetConid(const char *conname); +extern bool ConversionIsVisible(Oid conid); extern void DeconstructQualifiedName(List *names, char **nspname_p, -- 2.40.0