Skip to content

Commit

Permalink
Add cast to null when no way to cast
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Nov 21, 2024
1 parent cec2995 commit 389ef57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/backend/parser/parse_coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/include/parser/parse_coerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 389ef57

Please sign in to comment.