@@ -29,7 +29,7 @@ CREATE OR REPLACE FUNCTION to_schema_qualified_operator(opid oid) RETURNS TEXT A
2929into r;
3030
3131if r isnull then
32- raise exception' operator % does notexist ' , opid;
32+ raise exception' % is nota valid operator id ' , opid;
3333end if;
3434
3535ifr .oprleft = 0 then
@@ -61,6 +61,10 @@ CREATE OR REPLACE FUNCTION to_schema_qualified_type(typid oid) RETURNS TEXT AS $
6161on typnamespace= pg_namespace .oid
6262where pg_type .oid = typid
6363into result;
64+
65+ if result isnull then
66+ raise exception' % is not a valid type id' , typid;
67+ end if;
6468
6569return result;
6670END;
@@ -77,6 +81,10 @@ CREATE FUNCTION to_schema_qualified_relation(reloid oid) RETURNS TEXT AS $$
7781on relnamespace= pg_namespace .oid
7882where pg_class .oid = reloid
7983into result;
84+
85+ if result isnull then
86+ raise exception' % is not a valid relation id' , reloid;
87+ end if;
8088
8189return result;
8290END;
@@ -172,6 +180,11 @@ CREATE FUNCTION to_namespace(nsp text) RETURNS OID AS $$
172180from pg_catalog .pg_namespace
173181where nspname= nsp
174182into result;
183+
184+ if result isnull then
185+ raise exception' schema % does not exist' ,
186+ quote_literal(nsp);
187+ end if;
175188
176189return result;
177190END;
@@ -187,6 +200,10 @@ CREATE FUNCTION get_namespace(relation oid) RETURNS OID AS $$
187200from pg_catalog .pg_class
188201where oid = relation
189202into result;
203+
204+ if result isnull then
205+ raise exception' relation % does not exist' , relation;
206+ end if;
190207
191208return result;
192209END;
@@ -409,6 +426,9 @@ CREATE FUNCTION dump_statistic(schema_name text) RETURNS SETOF TEXT AS $$
409426itext ;
410427
411428BEGIN
429+ -- validate schema name
430+ select to_namespace(schema_name);
431+
412432for relidin
413433select pg_class .oid
414434from pg_catalog .pg_namespace
@@ -422,6 +442,11 @@ CREATE FUNCTION dump_statistic(schema_name text) RETURNS SETOF TEXT AS $$
422442end loop;
423443
424444return;
445+
446+ EXCEPTION
447+ when invalid_schema_name then
448+ raise exception' schema % does not exist' ,
449+ quote_literal(schema_name);
425450END;
426451$$ LANGUAGE plpgsql;
427452