From: Tom Lane Date: Sun, 10 Apr 2005 20:58:03 +0000 (+0000) Subject: Make constant-folding produce sane output for COALESCE(NULL,NULL), X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=6f9e49534aa1fbffaa4a8ac46d35ce2b3002868e;p=users%2Fbernd%2Fpostgres.git Make constant-folding produce sane output for COALESCE(NULL,NULL), that is a plain NULL and not a COALESCE with no inputs. Fixes crash reported by Michael Williamson. --- diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index ff36afc6f2..ccd0fe7392 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -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);