postgresqlmultidimensional-arraytypeinfo

Exact type information about multidimensional arrays in Postgres


Exact type information can be found in Postgres

I noticed that the type information is a bit inaccurate regarding miltidimensional arrays:

create table test (xid int[][] primary key);

insert into test values (array [[2, 4, 2, 7], [1, 5, 6, 0]])

select pg_typeof(xid) from test -- returns integer[]

How do I get back the exact type integer[][]?


Solution

  • This is the standard bevahior according to the manual :

    The current implementation does not enforce the declared number of dimensions either. Arrays of a particular element type are all considered to be of the same type, regardless of size or number of dimensions. So, declaring the array size or number of dimensions in CREATE TABLE is simply documentation; it does not affect run-time behavior.