Re: Documentation of EXCEPT ALL may have a bug - Mailing list pgsql-docs

From Tom Lane
Subject Re: Documentation of EXCEPT ALL may have a bug
Date
Msg-id 5573.1518289560@sss.pgh.pa.us
Whole thread Raw
In response to Re: Documentation of EXCEPT ALL may have a bug  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
List pgsql-docs
Alvaro Herrera <alvherre@alvh.no-ip.org> 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 <query expression> general rule 3) b) iii) 3) B),
on page 420 in the draft version I have.

            regards, tom lane


pgsql-docs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Functions in sort order - undocumented restriction
Next
From: "David G. Johnston"
Date:
Subject: Re: Functions in sort order - undocumented restriction