473,783 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*******@postg resql.org

Nov 12 '05 #1
3 13703
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*******@postg resql.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*******@postg resql.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
35133
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 who would find it useful? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
8
2433
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. Can someone share their experiences why someone should use those operators and what type of scenarios? Any good snippets and example?
1
1266
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 is there a smarter way? TIA --
2
2829
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 thanks in adavnace. error: C:\Progs\ARCommand2003\InvoicePrePrintedContract\frmPreview.cs(387): Operator '||' cannot be applied to operands of type 'bool' and 'string' source = m_dsLocal.Tables.Rows.ToString(); SourcePrefix =...
5
8451
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 = "Login already exists" End If If (checkLogin And 2) And txtEmpNum.Text <> 0 Then
2
4121
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 'int' and 'int' The code is the following : // MASKS.Insert = 2 if (_RightMask && (int)MASKS.Insert)
5
6276
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 to do this in c#? Thanks,
9
3749
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'); printf("%d", a); /* code end */ 2
1
2395
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 Truth Tables, and B) Upon terminating the program, display a message as follows: “Thank you for using the Logical Operator Truth Table Display Program: ‘Your full name’ “ Here's the program. Need advice on switch structure...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.