(ie, the one with describe-schema support). Minor code review.
Adjust display of casts to use standard type names.
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.83 2003/01/07 18:46:52 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.84 2003/01/07 20:56:06 tgl Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><literal>\dc</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
+ <listitem>
+ <para>
+ Lists all available conversions between character-set encodings.
+ If <replaceable class="parameter">pattern</replaceable>
+ is specified, only conversions whose name matches the pattern are
+ listed.
+ </para>
+ </listitem>
+ </varlistentry>
+
+
+ <varlistentry>
+ <term><literal>\dC</literal></term>
+ <listitem>
+ <para>
+ Lists all available type casts.
+ </para>
+ </listitem>
+ </varlistentry>
+
+
<varlistentry>
<term><literal>\dd</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
<listitem>
</varlistentry>
- <varlistentry>
- <term><literal>\dc</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
- <listitem>
- <para>
- Lists all available conversions (between encodings). If <replaceable
- class="parameter">pattern</replaceable>
- is specified, only matching conversions are shown.
- </para>
- </listitem>
- </varlistentry>
-
-
- <varlistentry>
- <term><literal>\dC</literal></term>
- <listitem>
- <para>
- 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.
- </para>
- </listitem>
- </varlistentry>
-
-
<varlistentry>
<term><literal>\df [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
</varlistentry>
+ <varlistentry>
+ <term><literal>\dn</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
+
+ <listitem>
+ <para>
+ Lists all available schemas (namespaces). If <replaceable
+ class="parameter">pattern</replaceable> (a regular expression)
+ is specified, only schemas whose name matches the pattern are listed.
+ </para>
+ </listitem>
+ </varlistentry>
+
+
<varlistentry>
<term><literal>\do [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
<listitem>
</para>
<note>
<para>
- This command does not see changes made by <command>SET
- CLIENT_ENCODING</>.
+ This command will not notice changes made directly by <command>SET
+ CLIENT_ENCODING</>. If you use <literal>\encoding</literal>,
+ be sure to use it to set as well as examine the encoding.
</para>
</note>
</listitem>
* 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 $
*
*-------------------------------------------------------------------------
*/
Datum pg_opclass_is_visible(PG_FUNCTION_ARGS);
Datum pg_conversion_is_visible(PG_FUNCTION_ARGS);
+
/*
* RangeVarGetRelid
* Given a RangeVar describing an existing relation,
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();
* 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);
*
* 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"
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;
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;
}
*
* 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"
" 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,
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"
" 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);
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
*
*
* 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
/* \dC */
bool listCasts(const char *pattern);
+/* \dn */
+bool listSchemas(const char *pattern);
+
#endif /* DESCRIBE_H */
*
* 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"
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"));
* 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 $
*
*-------------------------------------------------------------------------
*/
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,