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 1ekaTU-00063t-Iv for pgsql-docs@arkaria.postgresql.org; Sat, 10 Feb 2018 19:06:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ekaTT-0002W0-A2 for pgsql-docs@arkaria.postgresql.org; Sat, 10 Feb 2018 19:06:11 +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.84_2) (envelope-from ) id 1ekaTT-0002Vq-4o for pgsql-docs@lists.postgresql.org; Sat, 10 Feb 2018 19:06:11 +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 1ekaTM-000365-Bb for pgsql-docs@lists.postgresql.org; Sat, 10 Feb 2018 19:06:10 +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 w1AJ60pH005574; Sat, 10 Feb 2018 14:06:00 -0500 From: Tom Lane To: Alvaro Herrera cc: jao@geophile.com, pgsql-docs@lists.postgresql.org Subject: Re: Documentation of EXCEPT ALL may have a bug In-reply-to: <20180210115937.aqoolac4yk66ajeu@alvherre.pgsql> References: <20180210115937.aqoolac4yk66ajeu@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Sat, 10 Feb 2018 08:59:37 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5572.1518289560.1@sss.pgh.pa.us> Date: Sat, 10 Feb 2018 14:06:00 -0500 Message-ID: <5573.1518289560@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > PG Doc comments form wrote: >> create table t(x int); >> create table u(x int); >> >> insert into t values (1), (2), (2), (3), (3); >> insert into u values (1), (2); >> >> select * from t except all select * from u; >> x >> --- >> 3 >> 3 >> 2 >> (3 rows) > I find this pretty odd behavior. Is this not an outright bug? It's exactly what the standard says to do: if there are M occurrences of a row value in the LHS, and N occurrences in the RHS, emit max(M-N, 0) copies of the row. To my mind that's a reasonable definition of EXCEPT if you suppose that nominally-identical rows are matched and discarded one by one, rather than with de-duplication occurring beforehand. > [*] I didn't try terribly hard, but couldn't actually find where the > behavior is defined. In SQL:2011, it's 7.13 general rule 3) b) iii) 3) B), on page 420 in the draft version I have. regards, tom lane