exclusive OR possible within a where clause?

From: David Salisbury <salisbury(at)globe(dot)gov>
To: pgsql-general(at)postgresql(dot)org
Subject: exclusive OR possible within a where clause?
Date: 2011-10-13 23:44:50
Message-ID: 4E9777F2.9030303@globe.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I'm guessing that this isn't possible, but you guys are pretty smart. :)
Short version, is there a way to implement an exclusive OR in a where clause?

table1
dt1(timestamp)
---------
3 mins
5 mins
7 mins

table2
dt2(timestamp), timedifference(interval)
--------------- ----------------------
4 mins 1 min ( always positive )

I want to join these two tables, grabbing the row from table 1 that
has a time equal to table2's record + interval, but table 2 could
have values that fall smack dab in the middle of two table1 records,
and I don't want both.

select
t1.dt1
from
table1 t1,
table2 t2
where
t2.dt2 + t2.timedifference = t1.dt1
XOR ;-)
t2.dt2 - t2.timedifference = t1.dt1

It's not important which of the two closest times
I get, but would like to get just one without being
messy.

Thanks for any ideas. Maybe there's a great function out there
that solves this?

Dave

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2011-10-13 23:49:26 Re: Error: timestamp with timezone + interval is not immutable while creating index
Previous Message Anthony Presley 2011-10-13 23:33:57 Re: Drill-downs and OLAP type data