1919-- Helper functions to deal with cases where binary-coercible matches are
2020-- allowed.
2121-- This should match IsBinaryCoercible() in parse_coerce.c.
22+ -- It doesn't currently know about some cases, notably domains, anyelement,
23+ -- anynonarray, anyenum, or record, but it doesn't need to (yet).
2224create function binary_coercible(oid, oid) returns bool as $$
2325begin
2426 if $1 = $2 then return true; end if;
3941 return false;
4042end
4143$$ language plpgsql strict stable;
42- -- This one ignores castcontext, so it considers only physical equivalence
43- -- and not whether the coercion can be invoked implicitly.
44- create function physically_coercible(oid, oid) returns bool as $$
44+ -- This one ignores castcontext, so it will allow cases where an explicit
45+ -- (but still binary) cast would be required to convert the input type.
46+ -- We don't currently use this for any tests in this file, but it is a
47+ -- reasonable alternative definition for some scenarios.
48+ create function explicitly_binary_coercible(oid, oid) returns bool as $$
4549begin
4650 if $1 = $2 then return true; end if;
4751 if EXISTS(select 1 from pg_catalog.pg_cast where
@@ -1221,7 +1225,7 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999;
12211225
12221226-- Check that operators' underlying functions have suitable comments,
12231227-- namely 'implementation of XXX operator'. (Note: it's not necessary to
1224- -- put such comments into pg_proc.h ; initdb will generate them as needed.)
1228+ -- put such comments into pg_proc.dat ; initdb will generate them as needed.)
12251229-- In some cases involving legacy names for operators, there are multiple
12261230-- operators referencing the same pg_proc entry, so ignore operators whose
12271231-- comments say they are deprecated.
@@ -1323,7 +1327,6 @@ WHERE a.aggfnoid = p.oid AND
13231327(0 rows)
13241328
13251329-- Cross-check transfn against its entry in pg_proc.
1326- -- NOTE: use physically_coercible here, not binary_coercible, because
13271330SELECT a.aggfnoid::oid, p.proname, ptr.oid, ptr.proname
13281331FROM pg_aggregate AS a, pg_proc AS p, pg_proc AS ptr
13291332WHERE a.aggfnoid = p.oid AND
@@ -1332,15 +1335,16 @@ WHERE a.aggfnoid = p.oid AND
13321335 OR NOT (ptr.pronargs =
13331336 CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
13341337 ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
1335- OR NOT physically_coercible (ptr.prorettype, a.aggtranstype)
1336- OR NOT physically_coercible (a.aggtranstype, ptr.proargtypes[0])
1338+ OR NOT binary_coercible (ptr.prorettype, a.aggtranstype)
1339+ OR NOT binary_coercible (a.aggtranstype, ptr.proargtypes[0])
13371340 OR (p.pronargs > 0 AND
1338- NOT physically_coercible (p.proargtypes[0], ptr.proargtypes[1]))
1341+ NOT binary_coercible (p.proargtypes[0], ptr.proargtypes[1]))
13391342 OR (p.pronargs > 1 AND
1340- NOT physically_coercible (p.proargtypes[1], ptr.proargtypes[2]))
1343+ NOT binary_coercible (p.proargtypes[1], ptr.proargtypes[2]))
13411344 OR (p.pronargs > 2 AND
1342- NOT physically_coercible (p.proargtypes[2], ptr.proargtypes[3]))
1345+ NOT binary_coercible (p.proargtypes[2], ptr.proargtypes[3]))
13431346 -- we could carry the check further, but 3 args is enough for now
1347+ OR (p.pronargs > 3)
13441348 );
13451349 aggfnoid | proname | oid | proname
13461350----------+---------+-----+---------
@@ -1362,7 +1366,8 @@ WHERE a.aggfnoid = p.oid AND
13621366 NOT binary_coercible(p.proargtypes[1], pfn.proargtypes[2]))
13631367 OR (pfn.pronargs > 3 AND
13641368 NOT binary_coercible(p.proargtypes[2], pfn.proargtypes[3]))
1365- -- we could carry the check further, but 3 args is enough for now
1369+ -- we could carry the check further, but 4 args is enough for now
1370+ OR (pfn.pronargs > 4)
13661371 );
13671372 aggfnoid | proname | oid | proname
13681373----------+---------+-----+---------
@@ -1418,15 +1423,16 @@ WHERE a.aggfnoid = p.oid AND
14181423 OR NOT (ptr.pronargs =
14191424 CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
14201425 ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
1421- OR NOT physically_coercible (ptr.prorettype, a.aggmtranstype)
1422- OR NOT physically_coercible (a.aggmtranstype, ptr.proargtypes[0])
1426+ OR NOT binary_coercible (ptr.prorettype, a.aggmtranstype)
1427+ OR NOT binary_coercible (a.aggmtranstype, ptr.proargtypes[0])
14231428 OR (p.pronargs > 0 AND
1424- NOT physically_coercible (p.proargtypes[0], ptr.proargtypes[1]))
1429+ NOT binary_coercible (p.proargtypes[0], ptr.proargtypes[1]))
14251430 OR (p.pronargs > 1 AND
1426- NOT physically_coercible (p.proargtypes[1], ptr.proargtypes[2]))
1431+ NOT binary_coercible (p.proargtypes[1], ptr.proargtypes[2]))
14271432 OR (p.pronargs > 2 AND
1428- NOT physically_coercible (p.proargtypes[2], ptr.proargtypes[3]))
1433+ NOT binary_coercible (p.proargtypes[2], ptr.proargtypes[3]))
14291434 -- we could carry the check further, but 3 args is enough for now
1435+ OR (p.pronargs > 3)
14301436 );
14311437 aggfnoid | proname | oid | proname
14321438----------+---------+-----+---------
@@ -1441,15 +1447,16 @@ WHERE a.aggfnoid = p.oid AND
14411447 OR NOT (ptr.pronargs =
14421448 CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
14431449 ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
1444- OR NOT physically_coercible (ptr.prorettype, a.aggmtranstype)
1445- OR NOT physically_coercible (a.aggmtranstype, ptr.proargtypes[0])
1450+ OR NOT binary_coercible (ptr.prorettype, a.aggmtranstype)
1451+ OR NOT binary_coercible (a.aggmtranstype, ptr.proargtypes[0])
14461452 OR (p.pronargs > 0 AND
1447- NOT physically_coercible (p.proargtypes[0], ptr.proargtypes[1]))
1453+ NOT binary_coercible (p.proargtypes[0], ptr.proargtypes[1]))
14481454 OR (p.pronargs > 1 AND
1449- NOT physically_coercible (p.proargtypes[1], ptr.proargtypes[2]))
1455+ NOT binary_coercible (p.proargtypes[1], ptr.proargtypes[2]))
14501456 OR (p.pronargs > 2 AND
1451- NOT physically_coercible (p.proargtypes[2], ptr.proargtypes[3]))
1457+ NOT binary_coercible (p.proargtypes[2], ptr.proargtypes[3]))
14521458 -- we could carry the check further, but 3 args is enough for now
1459+ OR (p.pronargs > 3)
14531460 );
14541461 aggfnoid | proname | oid | proname
14551462----------+---------+-----+---------
@@ -1471,7 +1478,8 @@ WHERE a.aggfnoid = p.oid AND
14711478 NOT binary_coercible(p.proargtypes[1], pfn.proargtypes[2]))
14721479 OR (pfn.pronargs > 3 AND
14731480 NOT binary_coercible(p.proargtypes[2], pfn.proargtypes[3]))
1474- -- we could carry the check further, but 3 args is enough for now
1481+ -- we could carry the check further, but 4 args is enough for now
1482+ OR (pfn.pronargs > 4)
14751483 );
14761484 aggfnoid | proname | oid | proname
14771485----------+---------+-----+---------
@@ -1503,14 +1511,13 @@ WHERE a.aggfnoid = p.oid AND
15031511
15041512-- Check that all combine functions have signature
15051513-- combine(transtype, transtype) returns transtype
1506- -- NOTE: use physically_coercible here, not binary_coercible, because
15071514SELECT a.aggfnoid, p.proname
15081515FROM pg_aggregate as a, pg_proc as p
15091516WHERE a.aggcombinefn = p.oid AND
15101517 (p.pronargs != 2 OR
15111518 p.prorettype != p.proargtypes[0] OR
15121519 p.prorettype != p.proargtypes[1] OR
1513- NOT physically_coercible (a.aggtranstype, p.proargtypes[0]));
1520+ NOT binary_coercible (a.aggtranstype, p.proargtypes[0]));
15141521 aggfnoid | proname
15151522----------+---------
15161523(0 rows)
0 commit comments