PostgreSQL array_dims() Function
The PostgreSQL array_dims()
function returns a text representing the dimensions of the specified array.
array_dims()
Syntax
This is the syntax of the PostgreSQL array_dims()
function:
array_dims(array) -> text
Parameters
array
-
Required. The array to check.
Return value
The PostgreSQL array_dims()
function returns a text that represents dimensions of the specified array.
If the parameter array
is NULL
, the array_dims()
function will give an error message.
array_dims()
Examples
This example shows how to use the PostgreSQL array_dims()
function to obtain dimension information of the array {0,1,2}
.
SELECT array_dims(ARRAY[0, 1, 2]);
array_dims
------------
[1:3]
Here, the text [1:3]
represents that [0, 1, 2]
is a one-dimensional array with index from 1 to 3.
Let’s use the the PostgreSQL array_dims()
function to obtain the dimension information of a two-digit array, for example:
SELECT array_dims(ARRAY[[1,2], [3,4], [5,6]]);
array_dims
------------
[1:3][1:2]
Here, the text [1:3][1:2]
represents that [[1,2], [3,4], [5,6]]
is a two-dimensional array, where the first dimension array had index from 1 to 3, and the second dimension array had index from 1 to 2.
SELECT
array_dims(
ARRAY[
[[1,2,3], [4,5,6]],
[[7,8,9], [0,0,0]],
[[0,0,0], [0,0,0]]
]
);
array_dims
-----------------
[1:3][1:2][1:3]
Here, the text [1:3][1:2][1:3]
represents that the array specified is a three-dimensional array:
- The first dimension of the array has index from 1 to 3
- The second dimension of the array has index from 1 to 2
- The third dimension of the array has index from 1 to 3