From: Tatsuhito Kasahara <kasahara.tatsuhito@oss.ntt.co.jp>
To: dba <dbadbb@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Array issue....
Date: Mon, 14 Feb 2011 21:55:56 +0900
Message-ID: <4D59265C.9050505@oss.ntt.co.jp> (raw)
In-Reply-To: <1297684312397-3384334.post@n5.nabble.com>
References: <1297684312397-3384334.post@n5.nabble.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: kasahara.tatsuhito@oss.ntt.co.jp, dbadbb@gmail.com
Subject: Re: Array issue....
In-Reply-To: <4D59265C.9050505@oss.ntt.co.jp>
References: <1297684312397-3384334.post@n5.nabble.com> <4D59265C.9050505@oss.ntt.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox