array expression NULL fix [was: [HACKERS] odd behavior/possible bug] - Mailing list pgsql-patches

From Joe Conway
Subject array expression NULL fix [was: [HACKERS] odd behavior/possible bug]
Date
Msg-id 3F205E54.9070804@joeconway.com
Whole thread Raw
Responses Re: array expression NULL fix [was: [HACKERS] odd behavior/possible bug]
List pgsql-patches
Tom Lane wrote:
> Joe Conway <mail@joeconway.com> writes:
>>That probably makes good sense, at least until we can deal with NULL
>>elements. Would that patch count as a bug fix?
>
> Either one would count as a bug fix IMHO.  Anyone else have an opinion
> on which to do?

Here's a patch that replaces the ERROR with a NULL return value when an
element in an array expression is NULL.

Joe
Index: src/backend/executor/execQual.c
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/backend/executor/execQual.c,v
retrieving revision 1.135
diff -c -r1.135 execQual.c
*** src/backend/executor/execQual.c    21 Jul 2003 17:05:08 -0000    1.135
--- src/backend/executor/execQual.c    24 Jul 2003 22:44:44 -0000
***************
*** 1642,1650 ****

              dvalues[i++] = ExecEvalExpr(e, econtext, &eisnull, NULL);
              if (eisnull)
!                 ereport(ERROR,
!                         (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
!                          errmsg("arrays cannot have NULL elements")));
          }

          /* setup for 1-D array of the given length */
--- 1642,1651 ----

              dvalues[i++] = ExecEvalExpr(e, econtext, &eisnull, NULL);
              if (eisnull)
!             {
!                 *isNull = true;
!                 return (Datum) 0;
!             }
          }

          /* setup for 1-D array of the given length */
***************
*** 1686,1694 ****

              arraydatum = ExecEvalExpr(e, econtext, &eisnull, NULL);
              if (eisnull)
!                 ereport(ERROR,
!                         (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
!                          errmsg("arrays cannot have NULL elements")));

              array = DatumGetArrayTypeP(arraydatum);

--- 1687,1696 ----

              arraydatum = ExecEvalExpr(e, econtext, &eisnull, NULL);
              if (eisnull)
!             {
!                 *isNull = true;
!                 return (Datum) 0;
!             }

              array = DatumGetArrayTypeP(arraydatum);


pgsql-patches by date:

Previous
From: Larry Rosenman
Date:
Subject: Re: PG Patch (fwd) [openserver patch followup #2] (fwd)
Next
From: Bruce Momjian
Date:
Subject: Re: UPDATED Patch for adding DATACUBE operator