Re: exclusive OR possible within a where clause?

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: David Salisbury <salisbury(at)globe(dot)gov>
Cc: David Fetter <david(at)fetter(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: exclusive OR possible within a where clause?
Date: 2011-10-17 19:21:26
Message-ID: CAD3a31XrnhARSRAydokSUc_U=Ar9EC=QxRNP6+PtsskT4pqQRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you don't care about which row you get, how about adding a "LIMIT 1" to
your query? Don't know if that counts as "messy" or not... :)

On Mon, Oct 17, 2011 at 12:15 PM, David Salisbury <salisbury(at)globe(dot)gov>wrote:

>
>
> On 10/14/11 10:58 AM, David Fetter wrote:
>
>> On Thu, Oct 13, 2011 at 07:49:59PM -0400, Tom Lane wrote:
>>
>>> David Salisbury<salisbury(at)globe(dot)gov> writes:
>>>
>>
> Short version, is there a way to implement an exclusive OR in a where
>>>> clause?
>>>>
>>>
>>> The boolean<> operator will do the trick.
>>>
>>> (x = y)<> (a = b)
>>>
>>> regards, tom lane
>>>
>>
>> Factoring in NULLable columns, that's:
>>
>> (x IS NOT DISTINCT FROM y)<> (a IS NOT DISTINCT FROM b)
>>
>> Cheers,
>> David.
>>
>
> Thanks for the replies!
>
> I should note ( for the mail list archives I guess )
> that the above suggestions don't work. Both rows are
> returned whether I use OR or <>, though maybe I'm not
> understanding something. I'm not sure why <> would work either,
> as all I can find is <> is the same as !=, which is
> different than the fabled XOR I was hoping for. In fact
> they would never equal.
>
> But in the end it looks like wrapper sql around my output using
> "select distinct.." should do the trick.
>
> -Dave
>
>
> --
> 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<http://www.postgresql.org/mailpref/pgsql-general>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Salisbury 2011-10-17 19:40:32 Re: exclusive OR possible within a where clause?
Previous Message John R Pierce 2011-10-17 19:19:41 Re: exclusive OR possible within a where clause?