Skip to content

Commit 1ef60da

Browse files
committed
Don't let transform_null_equals=on affect CASE foo WHEN NULL ... constructs.
transform_null_equals is only supposed to affect "foo = NULL" expressions given directly by the user, not the internal "foo = NULL" expression generated from CASE-WHEN. This fixes bug #6242, reported by Sergey. Backpatch to all supported branches.
1 parent 041dceb commit 1ef60da

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/backend/parser/parse_expr.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,15 @@ transformAExprOp(ParseState *pstate, A_Expr *a)
836836
/*
837837
* Special-case "foo = NULL" and "NULL = foo" for compatibility with
838838
* standards-broken products (like Microsoft's). Turn these into IS NULL
839-
* exprs.
839+
* exprs. (If either side is a CaseTestExpr, then the expression was
840+
* generated internally from a CASE-WHEN expression, and
841+
* transform_null_equals does not apply.)
840842
*/
841843
if (Transform_null_equals &&
842844
list_length(a->name) == 1 &&
843845
strcmp(strVal(linitial(a->name)), "=") == 0 &&
844-
(exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)))
846+
(exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)) &&
847+
(!IsA(lexpr, CaseTestExpr) && !IsA(rexpr, CaseTestExpr)))
845848
{
846849
NullTest *n = makeNode(NullTest);
847850

0 commit comments

Comments
 (0)