From 389ef577cef1497095e0d18a65bbbe52d5950a34 Mon Sep 17 00:00:00 2001 From: Vladimir Rachkin Date: Thu, 21 Nov 2024 15:41:09 +0300 Subject: [PATCH] Add cast to null when no way to cast --- src/backend/parser/parse_coerce.c | 8 ++++++++ src/include/parser/parse_coerce.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index c88ed6119a..d6952b7c6d 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -1341,6 +1341,12 @@ build_coercion_expression(Node *node, return (Node *) iocoerce; } + else if (pathtype == COERCION_PATH_NONE_SAFE) { + Const *nullconst = makeNullConst(targetTypeId, targetTypMod, InvalidOid); + nullconst->location = location; + + return (Node *) nullconst; + } else { elog(ERROR, "unsupported pathtype %d in build_coercion_expression", @@ -2700,6 +2706,8 @@ find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, else if (ccontext >= COERCION_EXPLICIT && TypeCategory(sourceTypeId) == TYPCATEGORY_STRING) result = COERCION_PATH_COERCEVIAIO; + else if (ccontext == COERCION_EXPLICIT_SAFE) + result = COERCION_PATH_NONE_SAFE; } } diff --git a/src/include/parser/parse_coerce.h b/src/include/parser/parse_coerce.h index 87142dbfce..41804ead7c 100644 --- a/src/include/parser/parse_coerce.h +++ b/src/include/parser/parse_coerce.h @@ -24,6 +24,7 @@ typedef char TYPCATEGORY; typedef enum CoercionPathType { COERCION_PATH_NONE, /* failed to find any coercion pathway */ + COERCION_PATH_NONE_SAFE, /* failed to find any coercion pathway, but */ COERCION_PATH_FUNC, /* apply the specified coercion function */ COERCION_PATH_FUNC_SAFE, /* apply the specified coercion function safe */ COERCION_PATH_RELABELTYPE, /* binary-compatible cast, no function */