Make constant-folding produce sane output for COALESCE(NULL,NULL),
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 10 Apr 2005 20:58:03 +0000 (20:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
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 d8809a5252dff21dbb94ce54fd25657259c0fa0a..ae0c387e69a6a51427aad8ecbd19eeca5132ec4c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.154.2.2 2004/01/28 00:05:25 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.154.2.3 2005/04/10 20:58:03 tgl Exp $
  *
  * HISTORY
  *   AUTHOR            DATE            MAJOR EVENT
@@ -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);