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
14391440processNamePattern (& buf ,pattern , true, false,
14401441"n.nspname" ,"c.conname" ,NULL ,
@@ -1471,26 +1472,26 @@ listCasts(const char *pattern)
14711472initPQExpBuffer (& buf );
14721473/* NEED LEFT JOIN FOR BINARY CASTS */
14731474printfPQExpBuffer (& 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.oid ORDER 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
14951496res = PSQLexec (buf .data , false);
14961497termPQExpBuffer (& buf );
@@ -1506,6 +1507,48 @@ listCasts(const char *pattern)
15061507return true;
15071508}
15081509
1510+ /*
1511+ * \dn
1512+ *
1513+ * Describes schemas (namespaces)
1514+ */
1515+ bool
1516+ listSchemas (const char * pattern )
1517+ {
1518+ PQExpBufferData buf ;
1519+ PGresult * res ;
1520+ printQueryOpt myopt = 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 *