Add sanity check for pg_proc.provariadic

Check that the values from pg_proc.h match what ProcedureCreate would
have done.

Robert Haas and Amul Sul

Discussion: http://postgr.es/m/CA+TgmoZ_UGXfq5ygeDDMdUSJ4J_VX7nFnjC6mfY6BgOJ3qZCmw@mail.gmail.com
This commit is contained in:
Robert Haas 2017-10-31 09:52:39 +05:30
parent 86182b1895
commit 35f059e9bd
2 changed files with 34 additions and 0 deletions

View File

@ -129,6 +129,24 @@ WHERE p1.typinput = p2.oid AND NOT
-----+---------+-----+---------
(0 rows)
-- Check for type of the variadic array parameter's elements.
-- provariadic should be ANYOID if the type of the last element is ANYOID,
-- ANYELEMENTOID if the type of the last element is ANYARRAYOID, and otherwise
-- the element type corresponding to the array type.
SELECT oid::regprocedure, provariadic::regtype, proargtypes::regtype[]
FROM pg_proc
WHERE provariadic != 0
AND case proargtypes[array_length(proargtypes, 1)-1]
WHEN 2276 THEN 2276 -- any -> any
WHEN 2277 THEN 2283 -- anyarray -> anyelement
ELSE (SELECT t.oid
FROM pg_type t
WHERE t.typarray = proargtypes[array_length(proargtypes, 1)-1])
END != provariadic;
oid | provariadic | proargtypes
-----+-------------+-------------
(0 rows)
-- As of 8.0, this check finds refcursor, which is borrowing
-- other types' I/O routines
SELECT p1.oid, p1.typname, p2.oid, p2.proname

View File

@ -104,6 +104,22 @@ WHERE p1.typinput = p2.oid AND NOT
p2.proargtypes[1] = 'oid'::regtype AND
p2.proargtypes[2] = 'int4'::regtype));
-- Check for type of the variadic array parameter's elements.
-- provariadic should be ANYOID if the type of the last element is ANYOID,
-- ANYELEMENTOID if the type of the last element is ANYARRAYOID, and otherwise
-- the element type corresponding to the array type.
SELECT oid::regprocedure, provariadic::regtype, proargtypes::regtype[]
FROM pg_proc
WHERE provariadic != 0
AND case proargtypes[array_length(proargtypes, 1)-1]
WHEN 2276 THEN 2276 -- any -> any
WHEN 2277 THEN 2283 -- anyarray -> anyelement
ELSE (SELECT t.oid
FROM pg_type t
WHERE t.typarray = proargtypes[array_length(proargtypes, 1)-1])
END != provariadic;
-- As of 8.0, this check finds refcursor, which is borrowing
-- other types' I/O routines
SELECT p1.oid, p1.typname, p2.oid, p2.proname