@ -19,6 +19,8 @@
-- Helper functions to deal with cases where binary-coercible matches are
-- allowed.
-- This should match IsBinaryCoercible() in parse_coerce.c.
-- It doesn't currently know about some cases, notably domains, anyelement,
-- anynonarray, anyenum, or record, but it doesn't need to (yet).
create function binary_coercible(oid, oid) returns bool as $$
begin
if $1 = $2 then return true; end if;
@ -39,9 +41,11 @@ begin
return false;
end
$$ language plpgsql strict stable;
-- This one ignores castcontext, so it considers only physical equivalence
-- and not whether the coercion can be invoked implicitly.
create function physically_coercible(oid, oid) returns bool as $$
-- This one ignores castcontext, so it will allow cases where an explicit
-- (but still binary) cast would be required to convert the input type.
-- We don't currently use this for any tests in this file, but it is a
-- reasonable alternative definition for some scenarios.
create function explicitly_binary_coercible(oid, oid) returns bool as $$
begin
if $1 = $2 then return true; end if;
if EXISTS(select 1 from pg_catalog.pg_cast where
@ -1221,7 +1225,7 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999;
-- Check that operators' underlying functions have suitable comments,
-- namely 'implementation of XXX operator'. (Note: it's not necessary to
-- put such comments into pg_proc.h ; initdb will generate them as needed.)
-- put such comments into pg_proc.dat ; initdb will generate them as needed.)
-- In some cases involving legacy names for operators, there are multiple
-- operators referencing the same pg_proc entry, so ignore operators whose
-- comments say they are deprecated.
@ -1323,7 +1327,6 @@ WHERE a.aggfnoid = p.oid AND
(0 rows)
-- Cross-check transfn against its entry in pg_proc.
-- NOTE: use physically_coercible here, not binary_coercible, because
SELECT a.aggfnoid::oid, p.proname, ptr.oid, ptr.proname
FROM pg_aggregate AS a, pg_proc AS p, pg_proc AS ptr
WHERE a.aggfnoid = p.oid AND
@ -1332,15 +1335,16 @@ WHERE a.aggfnoid = p.oid AND
OR NOT (ptr.pronargs =
CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
OR NOT physicall y_coercible(ptr.prorettype, a.aggtranstype)
OR NOT physicall y_coercible(a.aggtranstype, ptr.proargtypes[0])
OR NOT binar y_coercible(ptr.prorettype, a.aggtranstype)
OR NOT binar y_coercible(a.aggtranstype, ptr.proargtypes[0])
OR (p.pronargs > 0 AND
NOT physicall y_coercible(p.proargtypes[0], ptr.proargtypes[1]))
NOT binar y_coercible(p.proargtypes[0], ptr.proargtypes[1]))
OR (p.pronargs > 1 AND
NOT physicall y_coercible(p.proargtypes[1], ptr.proargtypes[2]))
NOT binar y_coercible(p.proargtypes[1], ptr.proargtypes[2]))
OR (p.pronargs > 2 AND
NOT physicall y_coercible(p.proargtypes[2], ptr.proargtypes[3]))
NOT binar y_coercible(p.proargtypes[2], ptr.proargtypes[3]))
-- we could carry the check further, but 3 args is enough for now
OR (p.pronargs > 3)
);
aggfnoid | proname | oid | proname
----------+---------+-----+---------
@ -1362,7 +1366,8 @@ WHERE a.aggfnoid = p.oid AND
NOT binary_coercible(p.proargtypes[1], pfn.proargtypes[2]))
OR (pfn.pronargs > 3 AND
NOT binary_coercible(p.proargtypes[2], pfn.proargtypes[3]))
-- we could carry the check further, but 3 args is enough for now
-- we could carry the check further, but 4 args is enough for now
OR (pfn.pronargs > 4)
);
aggfnoid | proname | oid | proname
----------+---------+-----+---------
@ -1418,15 +1423,16 @@ WHERE a.aggfnoid = p.oid AND
OR NOT (ptr.pronargs =
CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
OR NOT physicall y_coercible(ptr.prorettype, a.aggmtranstype)
OR NOT physicall y_coercible(a.aggmtranstype, ptr.proargtypes[0])
OR NOT binar y_coercible(ptr.prorettype, a.aggmtranstype)
OR NOT binar y_coercible(a.aggmtranstype, ptr.proargtypes[0])
OR (p.pronargs > 0 AND
NOT physicall y_coercible(p.proargtypes[0], ptr.proargtypes[1]))
NOT binar y_coercible(p.proargtypes[0], ptr.proargtypes[1]))
OR (p.pronargs > 1 AND
NOT physicall y_coercible(p.proargtypes[1], ptr.proargtypes[2]))
NOT binar y_coercible(p.proargtypes[1], ptr.proargtypes[2]))
OR (p.pronargs > 2 AND
NOT physicall y_coercible(p.proargtypes[2], ptr.proargtypes[3]))
NOT binar y_coercible(p.proargtypes[2], ptr.proargtypes[3]))
-- we could carry the check further, but 3 args is enough for now
OR (p.pronargs > 3)
);
aggfnoid | proname | oid | proname
----------+---------+-----+---------
@ -1441,15 +1447,16 @@ WHERE a.aggfnoid = p.oid AND
OR NOT (ptr.pronargs =
CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
OR NOT physicall y_coercible(ptr.prorettype, a.aggmtranstype)
OR NOT physicall y_coercible(a.aggmtranstype, ptr.proargtypes[0])
OR NOT binar y_coercible(ptr.prorettype, a.aggmtranstype)
OR NOT binar y_coercible(a.aggmtranstype, ptr.proargtypes[0])
OR (p.pronargs > 0 AND
NOT physicall y_coercible(p.proargtypes[0], ptr.proargtypes[1]))
NOT binar y_coercible(p.proargtypes[0], ptr.proargtypes[1]))
OR (p.pronargs > 1 AND
NOT physicall y_coercible(p.proargtypes[1], ptr.proargtypes[2]))
NOT binar y_coercible(p.proargtypes[1], ptr.proargtypes[2]))
OR (p.pronargs > 2 AND
NOT physicall y_coercible(p.proargtypes[2], ptr.proargtypes[3]))
NOT binar y_coercible(p.proargtypes[2], ptr.proargtypes[3]))
-- we could carry the check further, but 3 args is enough for now
OR (p.pronargs > 3)
);
aggfnoid | proname | oid | proname
----------+---------+-----+---------
@ -1471,7 +1478,8 @@ WHERE a.aggfnoid = p.oid AND
NOT binary_coercible(p.proargtypes[1], pfn.proargtypes[2]))
OR (pfn.pronargs > 3 AND
NOT binary_coercible(p.proargtypes[2], pfn.proargtypes[3]))
-- we could carry the check further, but 3 args is enough for now
-- we could carry the check further, but 4 args is enough for now
OR (pfn.pronargs > 4)
);
aggfnoid | proname | oid | proname
----------+---------+-----+---------
@ -1503,14 +1511,13 @@ WHERE a.aggfnoid = p.oid AND
-- Check that all combine functions have signature
-- combine(transtype, transtype) returns transtype
-- NOTE: use physically_coercible here, not binary_coercible, because
SELECT a.aggfnoid, p.proname
FROM pg_aggregate as a, pg_proc as p
WHERE a.aggcombinefn = p.oid AND
(p.pronargs != 2 OR
p.prorettype != p.proargtypes[0] OR
p.prorettype != p.proargtypes[1] OR
NOT physicall y_coercible(a.aggtranstype, p.proargtypes[0]));
NOT binar y_coercible(a.aggtranstype, p.proargtypes[0]));
aggfnoid | proname
----------+---------
(0 rows)