Postgres doesn't seem to enforce array dimensions

From: Joseph S <jks(at)selectacast(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Postgres doesn't seem to enforce array dimensions
Date: 2010-04-08 17:30:27
Message-ID: hpl3rj$1t8j$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What's up with Postgres and array dimensions? The table definition
doesn't even store how many dimensions the array should be.

[local]:playpen=> create table arrtest(
playpen(> id SERIAL PRIMARY KEY,
playpen(> arrone int[],
playpen(> arrtwo int[][]
playpen(> );
NOTICE: CREATE TABLE will create implicit sequence "arrtest_id_seq" for
serial column "arrtest.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"arrtest_pkey" for table "arrtest"
CREATE TABLE
Time: 22.688 ms
[local]:playpen=> INSERT into arrtest (arrone) VALUES (null); --should
work, and does
INSERT 0 1
Time: 3.798 ms
[local]:playpen=> INSERT into arrtest (arrone) VALUES ( ARRAY[1,2]);
INSERT 0 1
Time: 0.668 ms
[local]:playpen=> INSERT into arrtest (arrone) VALUES ( ARRAY[[3,4]]);
--should not work
INSERT 0 1
Time: 0.715 ms
[local]:playpen=> INSERT into arrtest (arrtwo) VALUES ( ARRAY[5,6]);
--should not work
INSERT 0 1
Time: 0.671 ms
[local]:playpen=> INSERT into arrtest (arrtwo) VALUES ( ARRAY[[7,8]]);
INSERT 0 1
Time: 0.704 ms
[local]:playpen=> select * from arrtest;
id | arrone | arrtwo
----+---------+---------
1 | |
2 | {1,2} |
3 | {{3,4}} |
4 | | {5,6}
5 | | {{7,8}}
(5 rows)

Time: 1.217 ms
[local]:playpen=> \d arrtest
Table "public.arrtest"
Column | Type | Modifiers
--------+-----------+------------------------------------------------------
id | integer | not null default nextval('arrtest_id_seq'::regclass)
arrone | integer[] |
arrtwo | integer[] |
Indexes:
"arrtest_pkey" PRIMARY KEY, btree (id)

[local]:playpen=> select version();
version

-----------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.6
20060404 (Red Hat 3.4.6-9), 32-bit

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2010-04-08 18:02:10 Re: Postgres doesn't seem to enforce array dimensions
Previous Message Jorge Arevalo 2010-04-08 17:04:28 Re: C-language functions: SRF question