Re: syntax sugar for conditional check

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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 22:22:59
Message-ID: 56FEF4C3.9010703@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 4/1/16 1:08 PM, Tom Lane wrote:
> 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.

It would prevent having to re-create that function every time... :)
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robbie Harwood 2016-04-01 22:34:56 Re: [PATCH v11] GSSAPI encryption support
Previous Message Tom Lane 2016-04-01 21:55:58 Re: pg_upgrade 9.6->9.6: column "amtype" does not exist