Re: Array issue....

From: Tatsuhito Kasahara <kasahara(dot)tatsuhito(at)oss(dot)ntt(dot)co(dot)jp>
To: dba <dbadbb(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Array issue....
Date: 2011-02-14 12:55:56
Message-ID: 4D59265C.9050505@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

dba wrote:
>
> I wanted to create index 0f 3 numeric array. But it is allowing to insert
> more than 4 elements
>
> CREATE TABLE abs(no int[3]);
> CREATE TABLE
>
> zivah=# INSERT INTO abs VALUES('{1,3,34,343,4342342,342}');
> INSERT 0 1
>
> I need a solution to store an elements exactly 3. More than 3 should not be
> allowed.
If you treat simple arrays, you may use "CHECK" as following example...

=# CREATE TABLE abs(no int[3], CHECK (array_upper(no, 1) < 3));
CREATE TABLE
=# INSERT INTO abs VALUES ('{1,2}');
INSERT 0 1
=# INSERT INTO abs VALUES ('{1,2,3}');
ERROR: 23514: new row for relation "abs" violates check constraint "abs_no_check"
LOCATION: ExecConstraints, execMain.c:2049

--
NTT OSS Center
Tatsuhito Kasahara

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2011-02-14 15:22:08 Re: BUG #5884: i cant select entire array values
Previous Message yashar ebrahimpoor 2011-02-14 12:55:08 BUG #5884: i cant select entire array values