Trying to get the length of array in array.
RAISE NOTICE '%', a[1][2][1]; -- ok, returns proper value
RAISE NOTICE '%', array_length(a, 1); -- ok, returns array length
But this won’t work:
RAISE NOTICE '%', array_length(a[1], 1); -- Error: function array_length(text, integer) does not exist
Why, if a[1] is array?
2
Answers
PostgreSQL’s arrays are not arrays of arrays like in some other languages. In PostgreSQL, there are only multidimensional arrays, and it is not easy to take slice. So your question in Postgres has not sense, just there are not sub arrays.
You can take info about the dimensions of the array:
or you can see the sizes
When you use not enough indexes, then Postgres try to make some slices, but when you don’t specify slice correctly, then you get NULL value (this is not the array), and then there cannot be used function
array_length
:Your slice is bad expressed, example on three dimensional array 2x2x2:
then since the slice is an array of an array you should ask for second dimension.
In the docs https://www.postgresql.org/docs/current/arrays.html