Re: Number of dimensions of an array parameter

From: Rod Taylor <pg(at)rbt(dot)ca>
To: Thomas Hallgren <thomas(at)tada(dot)se>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Number of dimensions of an array parameter
Date: 2006-05-08 18:03:17
Message-ID: 1147111397.93283.189.camel@home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> thhal=# CREATE DOMAIN twodims as int[][];
> CREATE DOMAIN

While still not perfect, you can use a CHECK constraint on the domain to
enforce dimension.

It's not perfect because domain constraints are not enforced in all
locations in versions earlier than 8.2. Adding extra explicit casts can
often work around that though.

ru=# create domain twodims as int[][] check(array_dims(value) =
'[1:2][1:2]');

ru=# select
array_dims('{{{1,2},{3,4}},{{5,3},{9,9}}}'::twodims);
ERROR: value for domain twodims violates check constraint
"twodims_check"

ru=# select array_dims('{{1,2},{3,4}}'::twodims);
array_dims
------------
[1:2][1:2]
(1 row)

If you want to be fancy, use something like this:

check(array_dims(value) ~ '^[1:\\d+][1:\\d+]$');

--

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2006-05-08 18:05:40 Re: Number of dimensions of an array parameter
Previous Message Kenneth Marshall 2006-05-08 18:01:36 Re: performance question (something to do w/