I\'m working on a project that collects information about your schema from the database directly. I can get the data_type
of the column using information_sche
For starters, the dimensionality of an array is not reflected in the data type in Postgres. The syntax integer[][]
is tolerated, but it's really just integer[]
internally.
Read the manual here.
This means, that dimensions can vary within the same data type (the same table column).
To get actual dimensions of a particular array value:
SELECT array_dims(my_arr); -- [1:2][1:3]
Or to just get the number of dimensions:
SELECT array_ndims(my_arr); -- 2
There are more array functions for similar needs. See table of array functions in the manual.
Related:
If you need to enforce particular dimensions in a column, add a CHECK constraint. To enforce 2-dimensional arrays:
ALTER TABLE tbl ADD CONSTRAINT tbl_arr_col_must_have_2_dims
CHECK (array_ndims(arr_col) = 2);