Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc8a4ce

Browse files
committed
add more sanity checks
1 parentfc3a400 commitbc8a4ce

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

‎contrib/dump_stat/dump_stat--1.0.sql

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CREATE OR REPLACE FUNCTION to_schema_qualified_operator(opid oid) RETURNS TEXT A
2929
into r;
3030

3131
if r isnull then
32-
raise exception'operator % does notexist', opid;
32+
raise exception'% is nota valid operator id', opid;
3333
end if;
3434

3535
ifr.oprleft=0 then
@@ -61,6 +61,10 @@ CREATE OR REPLACE FUNCTION to_schema_qualified_type(typid oid) RETURNS TEXT AS $
6161
on typnamespace=pg_namespace.oid
6262
wherepg_type.oid= typid
6363
into result;
64+
65+
if result isnull then
66+
raise exception'% is not a valid type id', typid;
67+
end if;
6468

6569
return result;
6670
END;
@@ -77,6 +81,10 @@ CREATE FUNCTION to_schema_qualified_relation(reloid oid) RETURNS TEXT AS $$
7781
on relnamespace=pg_namespace.oid
7882
wherepg_class.oid= reloid
7983
into result;
84+
85+
if result isnull then
86+
raise exception'% is not a valid relation id', reloid;
87+
end if;
8088

8189
return result;
8290
END;
@@ -172,6 +180,11 @@ CREATE FUNCTION to_namespace(nsp text) RETURNS OID AS $$
172180
frompg_catalog.pg_namespace
173181
where nspname= nsp
174182
into result;
183+
184+
if result isnull then
185+
raise exception'schema % does not exist',
186+
quote_literal(nsp);
187+
end if;
175188

176189
return result;
177190
END;
@@ -187,6 +200,10 @@ CREATE FUNCTION get_namespace(relation oid) RETURNS OID AS $$
187200
frompg_catalog.pg_class
188201
whereoid= relation
189202
into result;
203+
204+
if result isnull then
205+
raise exception'relation % does not exist', relation;
206+
end if;
190207

191208
return result;
192209
END;
@@ -409,6 +426,9 @@ CREATE FUNCTION dump_statistic(schema_name text) RETURNS SETOF TEXT AS $$
409426
itext;
410427

411428
BEGIN
429+
-- validate schema name
430+
select to_namespace(schema_name);
431+
412432
for relidin
413433
selectpg_class.oid
414434
frompg_catalog.pg_namespace
@@ -422,6 +442,11 @@ CREATE FUNCTION dump_statistic(schema_name text) RETURNS SETOF TEXT AS $$
422442
end loop;
423443

424444
return;
445+
446+
EXCEPTION
447+
when invalid_schema_name then
448+
raise exception'schema % does not exist',
449+
quote_literal(schema_name);
425450
END;
426451
$$ LANGUAGE plpgsql;
427452

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp