3
3
*
4
4
* Copyright 2000-2002 by PostgreSQL Global Development Group
5
5
*
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 $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "describe.h"
@@ -1426,15 +1426,16 @@ listConversions(const char *pattern)
1426
1426
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
1427
1427
" pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
1428
1428
" CASE WHEN c.condefault THEN '%s'\n"
1429
- " ELSE NULL END AS \"%s\"\n"
1429
+ " ELSE '%s' END AS \"%s\"\n"
1430
1430
"FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
1431
1431
"WHERE n.oid = c.connamespace\n" ,
1432
1432
_ ("Schema" ),
1433
1433
_ ("Name" ),
1434
1434
_ ("Source" ),
1435
- _ ("Dest" ),
1436
- _ ("default" ),
1437
- _ ("Modifier" ));
1435
+ _ ("Destination" ),
1436
+ _ ("yes" ),
1437
+ _ ("no" ),
1438
+ _ ("Default?" ));
1438
1439
1439
1440
processNamePattern (& buf , pattern , true, false,
1440
1441
"n.nspname" , "c.conname" , NULL ,
@@ -1471,26 +1472,26 @@ listCasts(const char *pattern)
1471
1472
initPQExpBuffer (& buf );
1472
1473
/* NEED LEFT JOIN FOR BINARY CASTS */
1473
1474
printfPQExpBuffer (& buf ,
1474
- "SELECT t1.typname AS \"%s\",\n"
1475
- " t2.typname AS \"%s\",\n"
1476
- " CASE WHEN p.proname IS NULL THEN '%s'\n"
1475
+ "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
1476
+ " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
1477
+ " CASE WHEN castfunc = 0 THEN '%s'\n"
1477
1478
" ELSE p.proname\n"
1478
1479
" END as \"%s\",\n"
1479
1480
" CASE WHEN c.castcontext = 'e' THEN '%s'\n"
1480
1481
" WHEN c.castcontext = 'a' THEN '%s'\n"
1481
1482
" ELSE '%s'\n"
1482
1483
" END as \"%s\"\n"
1483
1484
"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" ,
1486
1487
_ ("Source" ),
1487
1488
_ ("Target" ),
1488
1489
_ ("BINARY" ),
1489
1490
_ ("Function" ),
1490
- _ ("explicit " ),
1491
- _ ("assignment explicit " ),
1492
- _ ("implicit " ),
1493
- _ ("Context " ));
1491
+ _ ("no " ),
1492
+ _ ("in assignment " ),
1493
+ _ ("yes " ),
1494
+ _ ("Implicit? " ));
1494
1495
1495
1496
res = PSQLexec (buf .data , false);
1496
1497
termPQExpBuffer (& buf );
@@ -1506,6 +1507,48 @@ listCasts(const char *pattern)
1506
1507
return true;
1507
1508
}
1508
1509
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
+
1509
1552
/*
1510
1553
* processNamePattern
1511
1554
*
0 commit comments