469,327 Members | 1,242 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

XOR logical operator

Is there a XOR logical operator in Postgresql, or a
function for XOR ??

I only found in the docs a Binary XOR (#).

I need to do the following checkup:
(field1 is NULL XOR field2 is NULL XOR filed3 is NULL)

i can't right it like this:
(
(field1 is NUll or field2 is NUll)
and (field1 is NUll or field3 is NUll)
and (field2 is NUll or field3 is NUll)
)

But if i have alot of fields :
field1,field2,...,field5
.... this will take a hell of a time
I can write a function F1 that does the following:
if a field is NULL it will return 1
else it will return 0

then i can do:
(F1(field1) # F1(field2) # F1(field3) ...)
but i just wanted to see if XOR already exists ...

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #1
3 12208
Hello,

PostgreSQL hasn't logical operator XOR. But You can find it in cookbook
http://www.brasileiro.net/postgres/c...41&format=long

Regards
Pavel

On Fri, 17 Oct 2003, Nagib Abi Fadel wrote:
Is there a XOR logical operator in Postgresql, or a
function for XOR ??

I only found in the docs a Binary XOR (#).

I need to do the following checkup:
(field1 is NULL XOR field2 is NULL XOR filed3 is NULL)

i can't right it like this:
(
(field1 is NUll or field2 is NUll)
and (field1 is NUll or field3 is NUll)
and (field2 is NUll or field3 is NUll)
)

But if i have alot of fields :
field1,field2,...,field5
... this will take a hell of a time
I can write a function F1 that does the following:
if a field is NULL it will return 1
else it will return 0

then i can do:
(F1(field1) # F1(field2) # F1(field3) ...)
but i just wanted to see if XOR already exists ...

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #2
On Fri, 17 Oct 2003, Nagib Abi Fadel wrote:
Is there a XOR logical operator in Postgresql, or a
function for XOR ??

I only found in the docs a Binary XOR (#).

I need to do the following checkup:
(field1 is NULL XOR field2 is NULL XOR filed3 is NULL)
Good idea. hmmm

CREATE FUNCTION xor(bool,bool) RETURNS bool AS '
SELECT ($1 AND NOT $2) OR (NOT $1 AND $2);
' LANGUAGE 'sql';

CREATE OPERATOR ~| (PROCEDURE='xor',LEFTARG=bool,RIGHTARG=bool);

May not be all that neat but it does work so long as you use
brackets... I think improvements could be made. (10 minute job if that)

Peter Childs


i can't right it like this:
(
(field1 is NUll or field2 is NUll)
and (field1 is NUll or field3 is NUll)
and (field2 is NUll or field3 is NUll)
)

But if i have alot of fields :
field1,field2,...,field5
... this will take a hell of a time
I can write a function F1 that does the following:
if a field is NULL it will return 1
else it will return 0

then i can do:
(F1(field1) # F1(field2) # F1(field3) ...)
but i just wanted to see if XOR already exists ...

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #3
On Fri, 17 Oct 2003 01:04:48 -0700 (PDT), Nagib Abi Fadel
<na************@yahoo.com> wrote:
Is there a XOR logical operator in Postgresql


Yes: !=

Servus
Manfred

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

80 posts views Thread by Christopher Benson-Manica | last post: by
8 posts views Thread by Chua Wen Ching | last post: by
1 post views Thread by | last post: by
2 posts views Thread by Alpha | last post: by
5 posts views Thread by Dave | last post: by
2 posts views Thread by ThunderMusic | last post: by
5 posts views Thread by ano | last post: by
9 posts views Thread by marko | last post: by
1 post views Thread by ambanks04 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.