Skip site navigation (1) Skip section navigation (2)

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

From: Andreas <maps(dot)on(at)gmx(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: How to do A union (B - ( A intersect B )) or sort of :-)
Date: 2010-11-11 05:50:04
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Am 04.11.2010 20:53, schrieb A B:
> 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,,true from X
> B looks like    select,,false from Y

( A intersect B )  is allways the empty set because of the boolean 
column, isn't it?

Even if there were tupels  (,   =  (,
still  (,, TRUE) <>   (,, FALSE)
because of  TRUE <> FALSE
So  ( A intersect B )  =  ()

Therefore   ( B \ () )  =  B
So you end up with   A  union B  as Tom said.

The clever way to do the stuff w/o to many A- and B-subselects may be to 
create two temporary views and use those. There might be a performance 
loss though.

In response to

pgsql-novice by date

Next:From: Machiel RichardsDate: 2010-11-11 10:50:17
Subject: Postgresql 9 replication
Previous:From: AndreasDate: 2010-11-11 05:15:57
Subject: Re: Update a table from another table

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group