Re: syntax sugar for conditional check

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: Alexander Ostrow <aj(at)epcylon(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: syntax sugar for conditional check
Date: 2016-04-01 18:08:10
Message-ID: 32582.1459534090@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> writes:
> Rather than this, I think an exclusive-or operator would be a lot more
> useful. The only difficulty I run into with CHECK constaints is when I
> want to ensure that only ONE condition is true.

"bool != bool" works as XOR. If you need "exactly one of N" you could
do something like "(cond1::int + cond2::int + ...) = 1". We could
wrap some syntactic sugar around either of these, but it's not clear
to me that it'd be any more useful than a custom SQL function.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robbie Harwood 2016-04-01 19:00:07 Re: [PATCH v10] GSSAPI encryption support
Previous Message Pavel Stehule 2016-04-01 17:57:51 Re: syntax sugar for conditional check