Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the second argument in array_length() function?

Postgresql 9.4 has functions for array. One of them is array_length(anyarray, int). It get two argumetns.

What is the second argument? In all examples it has value 1. But nowhere says what it is.

like image 218
Haru Atari Avatar asked Dec 18 '15 13:12

Haru Atari


1 Answers

That's array's dimension.

Consider an example with a 2D array 3×2:

array_length(array[[1, 2], [3, 4], [5, 6]], 1) ---> 3
array_length(array[[1, 2], [3, 4], [5, 6]], 2) ---> 2

The size of the first dimension is 3; the size of the second dimension is 2.

like image 60
Sergey Kalinichenko Avatar answered Oct 15 '22 13:10

Sergey Kalinichenko