@@ -29,7 +29,7 @@ CREATE OR REPLACE FUNCTION to_schema_qualified_operator(opid oid) RETURNS TEXT A
29
29
into r;
30
30
31
31
if r isnull then
32
- raise exception' operator % does notexist ' , opid;
32
+ raise exception' % is nota valid operator id ' , opid;
33
33
end if;
34
34
35
35
ifr .oprleft = 0 then
@@ -61,6 +61,10 @@ CREATE OR REPLACE FUNCTION to_schema_qualified_type(typid oid) RETURNS TEXT AS $
61
61
on typnamespace= pg_namespace .oid
62
62
where pg_type .oid = typid
63
63
into result;
64
+
65
+ if result isnull then
66
+ raise exception' % is not a valid type id' , typid;
67
+ end if;
64
68
65
69
return result;
66
70
END;
@@ -77,6 +81,10 @@ CREATE FUNCTION to_schema_qualified_relation(reloid oid) RETURNS TEXT AS $$
77
81
on relnamespace= pg_namespace .oid
78
82
where pg_class .oid = reloid
79
83
into result;
84
+
85
+ if result isnull then
86
+ raise exception' % is not a valid relation id' , reloid;
87
+ end if;
80
88
81
89
return result;
82
90
END;
@@ -172,6 +180,11 @@ CREATE FUNCTION to_namespace(nsp text) RETURNS OID AS $$
172
180
from pg_catalog .pg_namespace
173
181
where nspname= nsp
174
182
into result;
183
+
184
+ if result isnull then
185
+ raise exception' schema % does not exist' ,
186
+ quote_literal(nsp);
187
+ end if;
175
188
176
189
return result;
177
190
END;
@@ -187,6 +200,10 @@ CREATE FUNCTION get_namespace(relation oid) RETURNS OID AS $$
187
200
from pg_catalog .pg_class
188
201
where oid = relation
189
202
into result;
203
+
204
+ if result isnull then
205
+ raise exception' relation % does not exist' , relation;
206
+ end if;
190
207
191
208
return result;
192
209
END;
@@ -409,6 +426,9 @@ CREATE FUNCTION dump_statistic(schema_name text) RETURNS SETOF TEXT AS $$
409
426
itext ;
410
427
411
428
BEGIN
429
+ -- validate schema name
430
+ select to_namespace(schema_name);
431
+
412
432
for relidin
413
433
select pg_class .oid
414
434
from pg_catalog .pg_namespace
@@ -422,6 +442,11 @@ CREATE FUNCTION dump_statistic(schema_name text) RETURNS SETOF TEXT AS $$
422
442
end loop;
423
443
424
444
return;
445
+
446
+ EXCEPTION
447
+ when invalid_schema_name then
448
+ raise exception' schema % does not exist' ,
449
+ quote_literal(schema_name);
425
450
END;
426
451
$$ LANGUAGE plpgsql;
427
452