Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jT6oV-0007Zf-6I for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Apr 2020 16:40:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jT6oU-0005A2-1n for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Apr 2020 16:40:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jT6oT-00059v-S4 for pgsql-bugs@lists.postgresql.org; Mon, 27 Apr 2020 16:40:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jT6oR-0008SU-5H for pgsql-bugs@lists.postgresql.org; Mon, 27 Apr 2020 16:40:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 03RGeqIR022035; Mon, 27 Apr 2020 12:40:52 -0400 From: Tom Lane To: "David G. Johnston" cc: "stephan@teeuwendesign.nl" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #16396: Parallel Union queries seem to treat NULL values differently In-reply-to: References: <16396-083a432fe7ac8fb9@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Mon, 27 Apr 2020 08:57:35 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22033.1588005652.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 27 Apr 2020 12:40:52 -0400 Message-ID: <22034.1588005652@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Monday, April 27, 2020, PG Bug reporting form > wrote: >> But as in our query the following happened: >> SELECT hello_world >> FROM (SELECT CAST(NULL AS INTEGER) AS hello_world) as a >> UNION >> SELECT hello_world >> FROM (SELECT NULL AS hello_world) as b >> It fails and is only fixable by defining the NULL in the right side of = the >> UNION as CAST(NULL AS INTEGER. > In the example the second null is untyped still when it gets fed to the > used and so can be implicitly cast to match the left side of the union. = In > you real case the null appears in a subquery under the from clause and > needs to be made into an actual type before it can be passed out of the > subquery and appear in the main query. The resultant type here is text. > Then the union happens and integer and text cannot be melded together. Yeah. I believe this changed in v10, at this commit: https://git.postgresql.org/gitweb/?p=3Dpostgresql.git&a=3Dcommitdiff&h=3D1= e7c4bb0049732ece651d993d03bb6772e5d281a Probably that should have been called out as an incompatibility in the v10 release notes, but I don't immediately see anything there that matches. In any case, it's intentional. regards, tom lane