473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 13598
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 me in something I'm working on). Am I the only one...
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 use it? I had some samples of c# codes using it. ...
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 can do it in three nested if-else statement, but...
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 this and tell me what I've done wrong? Many...
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 exists" If (checkLogin And 1) Then lbError.Text =...
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 : Operator '&&' cannot be applied to operands of type...
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 allow to use Operator "Or" with 'int'? If yes, how...
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 ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
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 FUNCTIONS which display the individual Logical Operator...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.