26

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.

Haru Atari
  • 1,502
  • 2
  • 17
  • 30

1 Answers1

32

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.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • 3
    Thank you very much. Can you give me a link to documentation where i can read this? – Haru Atari Dec 18 '15 at 13:35
  • 7
    @HaruAtari Unfortunately, the documentation for postgresql is somewhat scarce in comparison to the wealth of features supported by that RDBMS. Some features are documented only in passing, providing only a hint of what is going on. This function is a perfect example: the documentation to which you link says "returns the length of the *requested array dimension*", without an explanation that "requested dimension" is the second parameter or even an example showing a multi-dimension array. – Sergey Kalinichenko Dec 18 '15 at 13:41