7
7
-- Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8
8
-- Portions Copyright (c) 1994, Regents of the University of California
9
9
--
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 $
11
11
--
12
12
---------------------------------------------------------------------------
13
13
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
+
14
20
--
15
21
-- lists the name of all database adminstrators and the name of their
16
22
-- database(s)
@@ -23,127 +29,158 @@ SELECT usename, datname
23
29
--
24
30
-- lists all user-defined classes
25
31
--
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;
31
39
32
40
33
41
--
34
42
-- lists all simple indices (ie. those that are defined over one simple
35
43
-- column reference)
36
44
--
37
- SELECT bc.relname AS class_name,
45
+ SELECT n.nspname AS schema_name,
46
+ bc.relname AS class_name,
38
47
ic.relname AS index_name,
39
48
a.attname
40
- FROM pg_class bc, -- base class
49
+ FROM pg_namespace n,
50
+ pg_class bc, -- base class
41
51
pg_class ic, -- index class
42
52
pg_index i,
43
53
pg_attribute a -- att in base
44
- WHERE i.indrelid = bc.oid
54
+ WHERE bc.relnamespace = n.oid
55
+ and i.indrelid = bc.oid
45
56
and i.indexrelid = ic.oid
46
57
and i.indkey[0] = a.attnum
47
58
and i.indnatts = 1
48
59
and a.attrelid = bc.oid
49
- ORDER BY class_name, index_name, attname;
60
+ ORDER BY schema_name, class_name, index_name, attname;
50
61
51
62
52
63
--
53
64
-- lists the user-defined attributes and their types for all user-defined
54
65
-- classes
55
66
--
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
60
74
and a.attnum > 0 -- no system att's
75
+ and not a.attisdropped -- no dropped columns
61
76
and a.attrelid = c.oid
62
77
and a.atttypid = t.oid
63
- ORDER BY relname, attname;
78
+ ORDER BY nspname, relname, attname;
64
79
65
80
66
81
--
67
82
-- lists all user-defined base types (not including array types)
68
83
--
69
- SELECT u.usename, t. typname
70
- FROM pg_type t, pg_user u
84
+ SELECT n.nspname, u.usename, format_type(t.oid, null) as typname
85
+ FROM pg_type t, pg_user u, pg_namespace n
71
86
WHERE u.usesysid = t.typowner
87
+ and t.typnamespace = n.oid
72
88
and t.typrelid = '0'::oid -- no complex types
73
89
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;
76
93
77
94
78
95
--
79
96
-- lists all left unary operators
80
97
--
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
86
105
and o.oprright = right_type.oid
87
106
and o.oprresult = result.oid
88
- ORDER BY operand;
107
+ ORDER BY nspname, operand;
89
108
90
109
91
110
--
92
111
-- lists all right unary operators
93
112
--
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
99
120
and o.oprleft = left_type.oid
100
121
and o.oprresult = result.oid
101
- ORDER BY operand;
122
+ ORDER BY nspname, operand;
102
123
103
124
--
104
125
-- lists all binary operators
105
126
--
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
112
135
and o.oprleft = left_type.oid
113
136
and o.oprright = right_type.oid
114
137
and o.oprresult = result.oid
115
- ORDER BY left_opr, right_opr;
138
+ ORDER BY nspname, left_opr, right_opr;
116
139
117
140
118
141
--
119
142
-- lists the name, number of arguments and the return type of all user-defined
120
143
-- C functions
121
144
--
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
125
152
and p.prorettype = t.oid
126
153
and l.lanname = 'c'
127
- ORDER BY proname;
154
+ ORDER BY nspname, proname, pronargs, return_type ;
128
155
129
156
--
130
157
-- lists all aggregate functions and the types to which they can be applied
131
158
--
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
135
164
and p.proargtypes[0] = t.oid
136
- ORDER BY proname, typname;
165
+ ORDER BY nspname, proname, typname;
137
166
138
167
139
168
--
140
169
-- lists all the operator classes that can be used with each access method
141
170
-- as well as the operators that cn be used with the respective operator
142
171
-- classes
143
172
--
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
147
178
and amop.amopclaid = opc.oid
148
179
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
+
0 commit comments