aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-01-07 20:56:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-01-07 20:56:07 +0000
commitb4b62cff9343404edcf144df41765eb899d448bc (patch)
treedea2725fbb982d8d85643cfc2d84119cfd73e82d /src
parent1b59b442cee757f28a3951de698c706035d5e278 (diff)
downloadpostgresql-b4b62cff9343404edcf144df41765eb899d448bc.tar.gz
postgresql-b4b62cff9343404edcf144df41765eb899d448bc.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/namespace.c7
-rw-r--r--src/bin/psql/command.c25
-rw-r--r--src/bin/psql/describe.c71
-rw-r--r--src/bin/psql/describe.h5
-rw-r--r--src/bin/psql/help.c3
-rw-r--r--src/include/catalog/namespace.h5
6 files changed, 84 insertions, 32 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index fa0d20af307..0c571ca2a40 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 06d31598566..419e44a6326 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 d4f7e1ededd..0614b63da8d 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);
@@ -1507,6 +1508,48 @@ listCasts(const char *pattern)
}
/*
+ * \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
*
* Scan a wildcard-pattern option and generate appropriate WHERE clauses
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 6461b41d303..40a94b0efd2 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 e921f1da4b8..2dcf798d9dd 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 27e3e75168f..8bcd4876708 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,