Re: Check constraints for varchar[] and varchar[][] columns in a table

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Check constraints for varchar[] and varchar[][] columns in a table
Date: 2016-03-04 16:37:46
Message-ID: CAADeyWiVq5Bu52+owCytSZxmT2ZPRunoNpvPyT5PXMDy6xGK8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Okay, let's call it <~

:-)

On Fri, Mar 4, 2016 at 4:53 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Alexander Farber <alexander(dot)farber(at)gmail(dot)com> writes:
> > I am trying to add CHECK constraints to the VARCHAR arrays:
>
> > hand1 varchar[7] NOT NULL CHECK (ALL(hand1) ~ '^[*A-Z]$'),
>
> > but get syntax errors near "ALL"
> > - probably because that keyword is supposed to be on the right side?
>
> Yeah, the syntax has to be "scalar operator ALL (array)".
>
> > Could anyone please recommend a way to implement check constraints here?
>
> The workaround that's been suggested in the past is to define a reversed
> pattern match operator, ie one that has the pattern on the left. There's
> no such thing in the core PG distribution, but the only hard part of making
> your own is figuring out what to name the operator ;-)
>
> regards, tom lane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex Ignatov 2016-03-04 17:17:05 String literal doesn't autocast to text type
Previous Message Tom Lane 2016-03-04 15:53:33 Re: Check constraints for varchar[] and varchar[][] columns in a table