Re: Can I use a constraint to make sure all array elements are positive?
| От | Sergey Konoplev |
|---|---|
| Тема | Re: Can I use a constraint to make sure all array elements are positive? |
| Дата | |
| Msg-id | CAL_0b1vXy66xuJB5bO9_YtTCdUJDq5k+rgZ=uR5mAoBg+S_PZA@mail.gmail.com обсуждение исходный текст |
| Ответ на | Can I use a constraint to make sure all array elements are positive? (AlexK <alkuzo@gmail.com>) |
| Ответы |
Re: Can I use a constraint to make sure all array elements
are positive?
|
| Список | pgsql-sql |
On Wed, Mar 19, 2014 at 2:59 PM, AlexK <alkuzo@gmail.com> wrote:
> One of the columns in my table is FLOAT[] NOT NULL. Can I use a constraint to
> make sure all array elements are positive?
Sure, you can. Use all() in the CHECK constraint:
CREATE TABLE c (f float[] NOT NULL CHECK (0 < all(f)));
CREATE TABLE
INSERT INTO c VALUES (array[1,2,3]);
INSERT 0 1
INSERT INTO c VALUES (array[1,2,3,0]);
ERROR: new row for relation "c" violates check constraint "c_f_check"
DETAIL: Failing row contains ({1,2,3,0}).
--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA
http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray.ru@gmail.com
В списке pgsql-sql по дате отправления: