45

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.

0

1 Answer 1

56

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. Can you give me a link to documentation where i can read this?
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.