postgres.git / summary / log / commit / refs

commit    1ef60dab7049ffac52dee60b5788b6c7bc1f9d67
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Sat Oct 08 08:17:40 2011 +0000
First released in: 9.2.0, 8.2.23, 8.3.17, 8.4.10, 9.0.6, 9.1.2

    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.


src/backend/parser/parse_expr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 65d03adc494..79328c99797 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -836,12 +836,15 @@ transformAExprOp(ParseState *pstate, A_Expr *a) /* * Special-case "foo = NULL" and "NULL = foo" for compatibility with * standards-broken products (like Microsoft's). Turn these into IS NULL - * exprs. + * exprs. (If either side is a CaseTestExpr, then the expression was + * generated internally from a CASE-WHEN expression, and + * transform_null_equals does not apply.) */ if (Transform_null_equals && list_length(a->name) == 1 && strcmp(strVal(linitial(a->name)), "=") == 0 && - (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr))) + (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)) && + (!IsA(lexpr, CaseTestExpr) && !IsA(rexpr, CaseTestExpr))) { NullTest *n = makeNode(NullTest); [parent: 041dceb25900]