Re: Add a check an a array column

From: Bret Stern <bret_stern(at)machinemanagement(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Add a check an a array column
Date: 2012-09-08 20:18:25
Message-ID: 1347135505.2163.2.camel@fedora13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 2012-09-08 at 21:24 +0200, Andreas Kretschmer wrote:
> Joel Hoffman <joel(dot)hoffman(at)gmail(dot)com> wrote:
>
> > More concisely, you can compare directly against all values of the array:
> >
> > # create table i (i int[] check (0 <= ALL(i) AND 1023 >= ALL(i)));
> > # insert into i values (ARRAY[0,1,2,3,1023]);
> > # insert into i values (ARRAY[0,1,2,3,-1]);
> > ERROR: new row for relation "i" violates check constraint "i_i_check"
>
> Nice! Didn't know that with all()
>

A better place for validation is in the front-end, before
adding/attempting to add data to the db (my opinion).
Nice to see there are always other ways though.

>
> Andreas
> --
> Really, I'm not out to destroy Microsoft. That will just be a completely
> unintentional side effect. (Linus Torvalds)
> "If I was god, I would recompile penguin with --enable-fly." (unknown)
> Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Roman Golis 2012-09-09 01:55:20 copy from .. How to get rid of encoding check for bytea coumns
Previous Message Andreas Kretschmer 2012-09-08 19:24:14 Re: Add a check an a array column