Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id CDBF61337B79 for ; Mon, 14 Feb 2011 09:13:11 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 01022-09 for ; Mon, 14 Feb 2011 13:13:04 +0000 (UTC) X-Greylist: delayed 00:17:00.254764 by SQLgrey-1.7.6 Received: from serv2.oss.ntt.co.jp (serv2.oss.ntt.co.jp [222.151.198.100]) by mail.postgresql.org (Postfix) with ESMTP id EE1F31337990 for ; Mon, 14 Feb 2011 09:13:03 -0400 (AST) Received: from serv2.oss.ntt.co.jp (localhost [127.0.0.1]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 428B824836F; Mon, 14 Feb 2011 21:56:01 +0900 (JST) Received: from serv1.oss.ntt.co.jp (serv1.oss.ntt.co.jp [172.19.0.2]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 31A6524835E; Mon, 14 Feb 2011 21:56:01 +0900 (JST) Received: from [127.0.0.1] (unknown [172.17.1.127]) by serv1.oss.ntt.co.jp (Postfix) with ESMTP id 17021260766; Mon, 14 Feb 2011 21:56:01 +0900 (JST) Message-ID: <4D59265C.9050505@oss.ntt.co.jp> Date: Mon, 14 Feb 2011 21:55:56 +0900 From: Tatsuhito Kasahara User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: dba CC: pgsql-bugs@postgresql.org Subject: Re: Array issue.... References: <1297684312397-3384334.post@n5.nabble.com> In-Reply-To: <1297684312397-3384334.post@n5.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/122 X-Sequence-Number: 29394 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