How to do A union (B - ( A intersect B )) or sort of :-)

From: A B <gentosaker(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How to do A union (B - ( A intersect B )) or sort of :-)
Date: 2010-11-04 19:53:57
Message-ID: AANLkTikocZwZMmmkzihV+0Oqjb_F5uaZFMAassKVrBOS@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi.

Sorry for the subject, but I knew no words to describe it better.
I will try to explain

First a more general question: is there any clever way to do two
selects A and B and then return the result
A union ( B \ (A intersect B)) ( \ is "set subtraction")

Any ideas besides writing the explicit queries? I guess one has to
lock the table to get the same result on both selects unless one can
cache the result of A and B so you don't run it twice?

Then the actual problem at hand, which with extra details might result
in another solution then the one from above.

A looks like select a.id,a.name,true from X
B looks like select b.id,b.name,false from Y

can one then use the differences in boolean values in some clever way,
like OR operation?

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-11-04 20:43:41 Re: How to do A union (B - ( A intersect B )) or sort of :-)
Previous Message Thomas Kellerer 2010-11-04 16:53:59 Re: Function to spell out a number