Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f07rq-0007fY-9m for pgsql-bugs@arkaria.postgresql.org; Sun, 25 Mar 2018 15:47:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f07rp-00051Q-09 for pgsql-bugs@arkaria.postgresql.org; Sun, 25 Mar 2018 15:47:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f07ro-00051H-Qg for pgsql-bugs@lists.postgresql.org; Sun, 25 Mar 2018 15:47:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f07rh-0002CT-0y for pgsql-bugs@lists.postgresql.org; Sun, 25 Mar 2018 15:47:32 +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 w2PFhKYc031860; Sun, 25 Mar 2018 11:43:21 -0400 From: Tom Lane To: Andrew Gierth cc: pgsql-bugs@lists.postgresql.org, phb07@apra.asso.fr Subject: Re: BUG #15129: Problem with UNION/UNION ALL type setting when several NULL values before defining the proper type In-reply-to: <878tago8m2.fsf@news-spur.riddles.org.uk> References: <152196085023.32649.9916472370480121694@wrigleys.postgresql.org> <878tago8m2.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Sun, 25 Mar 2018 09:50:40 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31858.1521992600.1@sss.pgh.pa.us> Date: Sun, 25 Mar 2018 11:43:20 -0400 Message-ID: <31859.1521992600@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "PG" == PG Bug reporting form writes: > PG> While migrating a view from another RDBMS,I reached something that > PG> looks lie a bug in postgres. > It's not a bug in the code, though perhaps you could point out a place > where the documentation could be improved? It strikes me that section 10.5 doesn't say explicitly that multiple UNIONs are resolved pairwise. Someone who expected "x union y union z" to be resolved holistically, like a 3-way CASE would be, is not going to be enlightened by that section. Perhaps an additional example using this exact situation would be helpful. > (The SQL standard is of no particular help here since it does not allow > NULL to appear "bare", except in contextually typed expressions.) I think the SQL spec does offer considerable support for our pairwise resolution approach --- nowhere does it suggest that "x union y union z" is a construct that should be considered as a whole rather than as a nest of two independent union operations. regards, tom lane