> 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+]$');


-- 


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to