Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbBUe-0006Ml-EP for pgsql-bugs@arkaria.postgresql.org; Sat, 11 May 2013 15:13:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UbBUd-00007y-62 for pgsql-bugs@arkaria.postgresql.org; Sat, 11 May 2013 15:13:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbBUb-00007q-AU for pgsql-bugs@postgresql.org; Sat, 11 May 2013 15:13:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UbBUY-0006DT-Qh for pgsql-bugs@postgresql.org; Sat, 11 May 2013 15:13:49 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r4BFDihf016835; Sat, 11 May 2013 11:13:44 -0400 (EDT) From: Tom Lane To: brandstetter@falter.at cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8150: NULL emements lost when casting result of unnest() In-reply-to: References: Comments: In-reply-to brandstetter@falter.at message dated "Sat, 11 May 2013 12:22:48 -0000" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <16799.1368285135.0@sss.pgh.pa.us> Date: Sat, 11 May 2013 11:13:44 -0400 Message-ID: <16834.1368285224@sss.pgh.pa.us> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16799.1368285135.1@sss.pgh.pa.us> brandstetter@falter.at writes: > SELECT unnest('{1,NULL,4}'::int[])::int8; > i > --- > 1 > 4 Hm ... this seems to be a very old oversight in ExecMakeFunctionResult: when it's dealing with a set-valued function argument, if the function is strict and the particular input value is NULL, it sets the isDone flag to ExprEndResult, ie, empty-set result. I think this is the right thing if the current function returns set; but for a non-set-returning function, what we ought to get is a scalar NULL result not an empty set. Various other code paths including ExecMakeTableFunctionResult appear to get this right. The attached patch fixes it. This is another case where I'm not too sure if we ought to back-patch. The current behavior is clearly wrong, but perhaps some application out there will be unhappy if we change it in back branches? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-patch; charset="us-ascii" Content-ID: <16799.1368285135.2@sss.pgh.pa.us> Content-Description: fix-strict-non-srf-for-nulls.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQua= l.c index 4ea0cbadadbc14614d5e8182ec1da0ded631ee0f..c86a8456424df20e304f55c6de2= 628fa4f89db1f 100644 *** a/src/backend/executor/execQual.c --- b/src/backend/executor/execQual.c *************** restart: *** 1801,1812 **** pgstat_end_function_usage(&fcusage, rsinfo.isDone !=3D ExprMultipleResult); } ! else { result =3D (Datum) 0; *isNull =3D true; *isDone =3D ExprEndResult; } =20=20 /* Which protocol does function want to use? */ if (rsinfo.returnMode =3D=3D SFRM_ValuePerCall) --- 1801,1820 ---- pgstat_end_function_usage(&fcusage, rsinfo.isDone !=3D ExprMultipleResult); } ! else if (fcache->func.fn_retset) { + /* for a strict SRF, result is an empty set */ result =3D (Datum) 0; *isNull =3D true; *isDone =3D ExprEndResult; } + else + { + /* for a strict non-SRF, result is a NULL */ + result =3D (Datum) 0; + *isNull =3D true; + *isDone =3D ExprSingleResult; + } =20=20 /* Which protocol does function want to use? */ if (rsinfo.returnMode =3D=3D SFRM_ValuePerCall) ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--