Re: Execute query with EXCEPT, INTERSECT as anti-join, join? - Mailing list pgsql-hackers

From Colin 't Hart
Subject Re: Execute query with EXCEPT, INTERSECT as anti-join, join?
Date
Msg-id CAMon-aQLLAKBGc_pCRRmb92HPfoepUgV6-zd0ecLg2BqA+ch8Q@mail.gmail.com
Whole thread Raw
In response to Re: Execute query with EXCEPT, INTERSECT as anti-join, join?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Execute query with EXCEPT, INTERSECT as anti-join, join?
List pgsql-hackers
On 11 November 2013 14:34, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Colin 't Hart" <colinthart@gmail.com> writes:
>> I can't get Postgresql to execute a query with EXCEPT (or INTERSECT)
>> as an anti-join (or join).
>
>> Is this even possible?
>
> No, and it probably won't ever be, since the semantics aren't the same.
> EXCEPT/INTERSECT imply duplicate elimination.

Can't we just use DISTINCT for that?

Given a query

<query_1> EXCEPT <query_2>

isn't it always possible to rewrite this as

select distinct * from (<query_1>) q1 where not exists (select 1 from
(<query_2>) q2 where q1.col1 = q2.col1 and q1.col2 = c2.col2 and ...
and q1.colN = q2.colN)

?


Regards,

Colin



pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: streaming header too small
Next
From: Rafael Martinez
Date:
Subject: pg_dump and pg_dumpall in real life