Re: BUG #1591: BETWEEN NULL AND NULL causes crash

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Michael Williamson" <michael(dot)williamson(at)caseware(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1591: BETWEEN NULL AND NULL causes crash
Date: 2005-04-10 21:00:14
Message-ID: 15877.1113166814@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Michael Williamson" <michael(dot)williamson(at)caseware(dot)com> writes:
> SELECT * FROM Entities
> WHERE NULL IS NULL OR (EntityNo BETWEEN NULL AND COALESCE(NULL,NULL))
> This causes one of two results: postmaster crashes or goes into an infinite
> loop.

Good catch. COALESCE(NULL,NULL) is actually broken as far back as 7.4,
though I'm not sure if the error is visible in that version. If you
need the patch it's

Index: clauses.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v
retrieving revision 1.186.4.2
diff -c -r1.186.4.2 clauses.c
*** clauses.c 2 Feb 2005 21:49:43 -0000 1.186.4.2
--- clauses.c 10 Apr 2005 20:54:52 -0000
***************
*** 1771,1776 ****
--- 1771,1780 ----
newargs = lappend(newargs, e);
}

+ /* If all the arguments were constant null, the result is just null */
+ if (newargs == NIL)
+ return (Node *) makeNullConst(coalesceexpr->coalescetype);
+
newcoalesce = makeNode(CoalesceExpr);
newcoalesce->coalescetype = coalesceexpr->coalescetype;
newcoalesce->args = newargs;

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2005-04-10 21:18:14 Re: Unexpected behaviour of numeric datatype when mixed with, float4, domains and plpgsql variables
Previous Message Stephan Szabo 2005-04-10 20:25:49 Re: BUG #1590: Comparison Operation with Strings