diff options
Diffstat (limited to 'src/backend/parser/parse_coerce.c')
-rw-r--r-- | src/backend/parser/parse_coerce.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index c4e958e4aa8..60908111c82 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -2994,10 +2994,28 @@ IsPreferredType(TYPCATEGORY category, Oid type) bool IsBinaryCoercible(Oid srctype, Oid targettype) { + Oid castoid; + + return IsBinaryCoercibleWithCast(srctype, targettype, &castoid); +} + +/* IsBinaryCoercibleWithCast() + * Check if srctype is binary-coercible to targettype. + * + * This variant also returns the OID of the pg_cast entry if one is involved. + * *castoid is set to InvalidOid if no binary-coercible cast exists, or if + * there is a hard-wired rule for it rather than a pg_cast entry. + */ +bool +IsBinaryCoercibleWithCast(Oid srctype, Oid targettype, + Oid *castoid) +{ HeapTuple tuple; Form_pg_cast castForm; bool result; + *castoid = InvalidOid; + /* Fast path if same type */ if (srctype == targettype) return true; @@ -3061,6 +3079,9 @@ IsBinaryCoercible(Oid srctype, Oid targettype) result = (castForm->castmethod == COERCION_METHOD_BINARY && castForm->castcontext == COERCION_CODE_IMPLICIT); + if (result) + *castoid = castForm->oid; + ReleaseSysCache(tuple); return result; |