Re: exclusive OR possible within a where clause?

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'David Salisbury'" <salisbury(at)globe(dot)gov>, "'John R Pierce'" <pierce(at)hogranch(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: exclusive OR possible within a where clause?
Date: 2011-10-17 20:28:54
Message-ID: 01a401cc8d0b$652ee2f0$2f8ca8d0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of David Salisbury
Sent: Monday, October 17, 2011 3:41 PM
To: John R Pierce
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] exclusive OR possible within a where clause?

Perhaps what I'm hoping to do got munged. In essence it's equivalent of..

create table test ( something numeric ); insert into test values ( 1 );
insert into test values ( 2 );

select * from test where ( something = 1.5 + .5 ) or ( something = 1.5 - .5
);
something
-----------
1
2
(2 rows)

select * from test where ( something = 1.5 + .5 ) <> ( something = 1.5 - .5
);
something
-----------
1
2
(2 rows)

( which is of course equivalent of where something = 1 or something = 2 )

In my fabled XOR, I'd get the first one it matched, say something = 1, and
the something = 2 would then be ignored/dropped.

----------------------------------------------------------------------------
-------------

1) There is no concept of "FIRST" since you failed to include an ORDER BY
clause

2) Given that "something" can only take on a single value comparing it
against two separate (and different) values renders the difference between
OR and XOR meaningless.

If you want good help you need to give good examples - preferably real ones.

What you are trying to do has NOTHING to do with XOR. Provide a more
informative description of WHAT you are trying to do and additional REAL
sample data. From what you've described here, though, you probably want to
use WINDOW functions (RANK/ROW_NUMBER) in a sub-query and then look for only
those rows with RANK/ROW_NUMBER equal to 1.

David J.

--
Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org) To make
changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2011-10-17 20:59:42 Re: Video of Activity on PostgreSQL GIT repository
Previous Message David Salisbury 2011-10-17 20:27:21 Re: exclusive OR possible within a where clause?