472,342 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 13275
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

80
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to...
8
by: Chua Wen Ching | last post by:
Hi, I had some beginner questions. Do we need Shift << >> or Logical AND OR XOR operator in our daily programming? I am not sure why i need to...
1
by: | last post by:
Hi How would I compare a string to multiple values, ie. do this same action if string "abc" is equal to string X, or string Y or string Z? I know I...
2
by: Alpha | last post by:
Hi, I'm getting the following error message when I compile my program. I tried different things but it's not working. Can someone help me look at...
5
by: Dave | last post by:
I am a VB programmer tring to learn C# I am stuck on a bit operator "&" in VB: ' checkLogin = 3 means "Login exists" and "Employee Number...
2
by: ThunderMusic | last post by:
Hi, I have a value that contains flags that I must get using a bitmask. I tryied with the && operator, but the compiler outputs this error : ...
5
by: ano | last post by:
Hi, I have converted this VB code to C# but I got this error: "Operator '||' cannot be applied to operands of type 'int' and 'short'" Is VB...
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if (...
1
by: ambanks04 | last post by:
ok I have to do the following to a previous program A) Modify the program loop such that a ‘SWITCH’ structure is used to call each of the...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.