Make constant-folding produce sane output for COALESCE(NULL,NULL),
authorTom Lane <[email protected]>
Sun, 10 Apr 2005 20:58:03 +0000 (20:58 +0000)
committerTom Lane <[email protected]>
Sun, 10 Apr 2005 20:58:03 +0000 (20:58 +0000)
that is a plain NULL and not a COALESCE with no inputs.  Fixes crash
reported by Michael Williamson.

src/backend/optimizer/util/clauses.c

index ff36afc6f29763c2ac639c7a2176124d901d6b06..ccd0fe7392e2c032d7499ac3bbca09331301a308 100644 (file)
@@ -1553,6 +1553,10 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
                        FastAppend(&newargs, e);
                }
 
+               /* If all the arguments were constant null, the result is just null */
+               if (FastListValue(&newargs) == NIL)
+                       return (Node *) makeNullConst(coalesceexpr->coalescetype);
+
                newcoalesce = makeNode(CoalesceExpr);
                newcoalesce->coalescetype = coalesceexpr->coalescetype;
                newcoalesce->args = FastListValue(&newargs);