PostgreSQL array_ndims() Function
The PostgreSQL array_ndims()
function returns the number of dimensions of the specified array.
array_ndims()
Syntax
Here is the syntax of the PostgreSQL array_ndims()
function:
array_ndims(array) -> integer
Parameters
array
-
Required. The array.
Return value
The PostgreSQL array_ndims()
function returns an integer that is the number of dimensions of the specified array.
array_ndims()
Examples
This example shows how to use a PostgreSQL array_ndims()
function to return the number of dimensions of an array.
SELECT array_ndims(ARRAY[0, 1, 2]);
array_ndims
-------------
1
The result 1
means that the array ARRAY[0, 1, 2]
is a one-demension array.
You can also use the array_ndims()
function to return the number of dimensions of a multidimensional array, for example:
SELECT array_ndims('[2:4][2:3]={{1,1},{1,1},{1,1}}'::integer[]);
array_ndims
-------------
2
The result 1
means that the array [2:4][2:3]={{1,1},{1,1},{1,1}}
is a two-demension array.