77-- Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88-- Portions Copyright (c) 1994, Regents of the University of California
99--
10- -- $Id: syscat.source,v 1.9 2003/08/04 23:59:41 tgl Exp $
10+ -- $Id: syscat.source,v 1.10 2003/10/26 04:51:51 momjian Exp $
1111--
1212---------------------------------------------------------------------------
1313
14+ --
15+ -- Sets the schema search path to pg_catalog first, so that we do not
16+ -- need to qualify every system object
17+ --
18+ SET SEARCH_PATH TO pg_catalog;
19+
1420--
1521-- lists the name of all database adminstrators and the name of their
1622-- database(s)
@@ -23,127 +29,158 @@ SELECT usename, datname
2329--
2430-- lists all user-defined classes
2531--
26- SELECT relname
27- FROM pg_class
28- WHERE relkind = 'r' -- not indices, views, etc
29- and relname !~ '^pg_' -- not catalogs
30- ORDER BY relname;
32+ SELECT pgn.nspname, pgc.relname
33+ FROM pg_class pgc, pg_namespace pgn
34+ WHERE pgc.relnamespace=pgn.oid
35+ and pgc.relkind = 'r' -- not indices, views, etc
36+ and pgn.nspname not like 'pg_%' -- not catalogs
37+ and pgn.nspname != 'information_schema' -- not information_schema
38+ ORDER BY nspname, relname;
3139
3240
3341--
3442-- lists all simple indices (ie. those that are defined over one simple
3543-- column reference)
3644--
37- SELECT bc.relname AS class_name,
45+ SELECT n.nspname AS schema_name,
46+ bc.relname AS class_name,
3847 ic.relname AS index_name,
3948 a.attname
40- FROM pg_class bc, -- base class
49+ FROM pg_namespace n,
50+ pg_class bc, -- base class
4151 pg_class ic, -- index class
4252 pg_index i,
4353 pg_attribute a -- att in base
44- WHERE i.indrelid = bc.oid
54+ WHERE bc.relnamespace = n.oid
55+ and i.indrelid = bc.oid
4556 and i.indexrelid = ic.oid
4657 and i.indkey[0] = a.attnum
4758 and i.indnatts = 1
4859 and a.attrelid = bc.oid
49- ORDER BY class_name, index_name, attname;
60+ ORDER BYschema_name, class_name, index_name, attname;
5061
5162
5263--
5364-- lists the user-defined attributes and their types for all user-defined
5465-- classes
5566--
56- SELECT c.relname, a.attname, t.typname
57- FROM pg_class c, pg_attribute a, pg_type t
58- WHERE c.relkind = 'r' -- no indices
59- and c.relname !~ '^pg_' -- no catalogs
67+ SELECT n.nspname, c.relname, a.attname, format_type(t.oid, null) as typname
68+ FROM pg_namespace n, pg_class c,
69+ pg_attribute a, pg_type t
70+ WHERE n.oid = c.relnamespace
71+ and c.relkind = 'r' -- no indices
72+ and n.nspname not like 'pg_%' -- no catalogs
73+ and n.nspname != 'information_schema' -- no information_schema
6074 and a.attnum > 0 -- no system att's
75+ and not a.attisdropped -- no dropped columns
6176 and a.attrelid = c.oid
6277 and a.atttypid = t.oid
63- ORDER BY relname, attname;
78+ ORDER BYnspname, relname, attname;
6479
6580
6681--
6782-- lists all user-defined base types (not including array types)
6883--
69- SELECT u.usename,t. typname
70- FROM pg_type t, pg_user u
84+ SELECTn.nspname, u.usename,format_type(t.oid, null) as typname
85+ FROM pg_type t, pg_user u, pg_namespace n
7186 WHERE u.usesysid = t.typowner
87+ and t.typnamespace = n.oid
7288 and t.typrelid = '0'::oid -- no complex types
7389 and t.typelem = '0'::oid -- no arrays
74- and u.usename <> 'postgres'
75- ORDER BY usename, typname;
90+ and n.nspname not like 'pg_%' -- no catalogs
91+ and n.nspname != 'information_schema' -- no information_schema
92+ ORDER BY nspname, usename, typname;
7693
7794
7895--
7996-- lists all left unary operators
8097--
81- SELECT o.oprname AS left_unary,
82- right_type.typname AS operand,
83- result.typname AS return_type
84- FROM pg_operator o, pg_type right_type, pg_type result
85- WHERE o.oprkind = 'l' -- left unary
98+ SELECT n.nspname, o.oprname AS left_unary,
99+ format_type(right_type.oid, null) AS operand,
100+ format_type(result.oid, null) AS return_type
101+ FROM pg_namespace n, pg_operator o,
102+ pg_type right_type, pg_type result
103+ WHERE o.oprnamespace = n.oid
104+ and o.oprkind = 'l' -- left unary
86105 and o.oprright = right_type.oid
87106 and o.oprresult = result.oid
88- ORDER BY operand;
107+ ORDER BYnspname, operand;
89108
90109
91110--
92111-- lists all right unary operators
93112--
94- SELECT o.oprname AS right_unary,
95- left_type.typname AS operand,
96- result.typname AS return_type
97- FROM pg_operator o, pg_type left_type, pg_type result
98- WHERE o.oprkind = 'r' -- right unary
113+ SELECT n.nspname, o.oprname AS right_unary,
114+ format_type(left_type.oid, null) AS operand,
115+ format_type(result.oid, null) AS return_type
116+ FROM pg_namespace n, pg_operator o,
117+ pg_type left_type, pg_type result
118+ WHERE o.oprnamespace = n.oid
119+ and o.oprkind = 'r' -- right unary
99120 and o.oprleft = left_type.oid
100121 and o.oprresult = result.oid
101- ORDER BY operand;
122+ ORDER BYnspname, operand;
102123
103124--
104125-- lists all binary operators
105126--
106- SELECT o.oprname AS binary_op,
107- left_type.typname AS left_opr,
108- right_type.typname AS right_opr,
109- result.typname AS return_type
110- FROM pg_operator o, pg_type left_type, pg_type right_type, pg_type result
111- WHERE o.oprkind = 'b' -- binary
127+ SELECT n.nspname, o.oprname AS binary_op,
128+ format_type(left_type.oid, null) AS left_opr,
129+ format_type(right_type.oid, null) AS right_opr,
130+ format_type(result.oid, null) AS return_type
131+ FROM pg_namespace n, pg_operator o, pg_type left_type,
132+ pg_type right_type, pg_type result
133+ WHERE o.oprnamespace = n.oid
134+ and o.oprkind = 'b' -- binary
112135 and o.oprleft = left_type.oid
113136 and o.oprright = right_type.oid
114137 and o.oprresult = result.oid
115- ORDER BY left_opr, right_opr;
138+ ORDER BYnspname, left_opr, right_opr;
116139
117140
118141--
119142-- lists the name, number of arguments and the return type of all user-defined
120143-- C functions
121144--
122- SELECT p.proname, p.pronargs, t.typname
123- FROM pg_proc p, pg_language l, pg_type t
124- WHERE p.prolang = l.oid
145+ SELECT n.nspname, p.proname, p.pronargs, format_type(t.oid, null) as return_type
146+ FROM pg_namespace n, pg_proc p,
147+ pg_language l, pg_type t
148+ WHERE p.pronamespace = n.oid
149+ and n.nspname not like 'pg_%' -- no catalogs
150+ and n.nspname != 'information_schema' -- no information_schema
151+ and p.prolang = l.oid
125152 and p.prorettype = t.oid
126153 and l.lanname = 'c'
127- ORDER BY proname;
154+ ORDER BYnspname, proname, pronargs, return_type ;
128155
129156--
130157-- lists all aggregate functions and the types to which they can be applied
131158--
132- SELECT p.proname, t.typname
133- FROM pg_aggregate a, pg_proc p, pg_type t
134- WHERE a.aggfnoid = p.oid
159+ SELECT n.nspname, p.proname, format_type(t.oid, null) as typname
160+ FROM pg_namespace n, pg_aggregate a,
161+ pg_proc p, pg_type t
162+ WHERE p.pronamespace = n.oid
163+ and a.aggfnoid = p.oid
135164 and p.proargtypes[0] = t.oid
136- ORDER BY proname, typname;
165+ ORDER BYnspname, proname, typname;
137166
138167
139168--
140169-- lists all the operator classes that can be used with each access method
141170-- as well as the operators that cn be used with the respective operator
142171-- classes
143172--
144- SELECT am.amname, opc.opcname, opr.oprname
145- FROM pg_am am, pg_opclass opc, pg_amop amop, pg_operator opr
146- WHERE opc.opcamid = am.oid
173+ SELECT n.nspname, am.amname, opc.opcname, opr.oprname
174+ FROM pg_namespace n, pg_am am, pg_opclass opc,
175+ pg_amop amop, pg_operator opr
176+ WHERE opc.opcnamespace = n.oid
177+ and opc.opcamid = am.oid
147178 and amop.amopclaid = opc.oid
148179 and amop.amopopr = opr.oid
149- ORDER BY amname, opcname, oprname;
180+ ORDER BY nspname, amname, opcname, oprname;
181+
182+ --
183+ -- Reset the search path
184+ --
185+ RESET SEARCH_PATH;
186+