From: | Domoszlai László <dlacko(at)finit(dot)hu> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "SQL PostgreSQL (E-mail)" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: set difference |
Date: | 2002-10-16 13:44:42 |
Message-ID: | D6CD29CE4DF67F47A11FB6CF5EBE15D1375753@gedeon.finit.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Tom Lane wrote:
> > I would like to make symmetrical(set) difference in a query.
> > But the simpliest way I could find is
>
> > select id from a
> > except
> > select id from b
> > union
> > select id from b
> > except
> > select id from a
>
> > Is there any better solution for this problem?
>
> One thing you should definitely do is change "union" to "union all".
> "union" implies a pass of duplicate removal, which shouldn't be
> necessary here (unless a or b individually contain duplicates and
> you want to get rid of those too).
>
> Another thing to try is
> (a union b) except (a intersect b)
> (Again, you might be able to say union all instead of union.)
> Not sure which will be faster.
It's likely faster but my problem is I have to run queries twice. I've looked at
setOp executor and it seems symmetrical differencial can run as time as an EXCEPT.
I would write it, because it speeds up my query very much, but I don't know if it is worth. So, do you think a DIFFERENCE or EXCEPT SYMMETRIC clause will be reasonable
feauture for postgresql?
Laca
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-10-16 13:57:37 | Re: set difference |
Previous Message | Ian Barwick | 2002-10-16 12:16:08 | Re: replace null with 0 in subselect ? |