Re: Number of dimensions of an array parameter - Mailing list pgsql-hackers

From Rod Taylor
Subject Re: Number of dimensions of an array parameter
Date
Msg-id 1147111397.93283.189.camel@home
Whole thread Raw
In response to Number of dimensions of an array parameter  (Thomas Hallgren <thomas@tada.se>)
List 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+]$');


-- 



pgsql-hackers by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: Pragma linking?
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Number of dimensions of an array parameter