On 19 January 2014 11:43, Marko Tiikkaja <marko@joh.to> wrote:
>
>
> On 1/19/14, 9:12 AM, Dean Rasheed wrote:
>>
>> On 18 January 2014 03:07, Marko Tiikkaja <marko@joh.to> wrote:
>>>
>>> Here's the patch as promised. Thoughts?
>>>
>>
>> A couple of points:
>>
>> The answer for empty (zero dimensional) arrays is wrong --- you need
>> special case handling for this case to return 0.
>
>
> How embarrassing. I don't know why I removed that check or how I didn't
> catch the clearly wrong answer in the test output.
>
>
>> In fact why not
>> simply use ArrayGetNItems()?
>
>
> Even better. Changed.
>
>
>> In the docs, in the table of array functions, I think it would
>> probably be useful to make the entry for array_length say "see also
>> cardinality", otherwise people might just stop reading there. I
>> suspect that in over 90% of cases, cardinality will be the more
>> appropriate function to use rather than array_length.
>
>
> I don't see this as a huge improvement, but even worse, I don't see a way to
> naturally fit it into the description.
>
Hmm. Looking at that page in the docs, it currently doesn't even
mention that array_length returns NULL for empty arrays, or more
generally for arrays that don't have the requested dimension. To
someone unfamiliar with postgresql arrays, that could lead to a nasty
surprise.
How about having the array_length docs say something like
returns the length of the requested array dimension, or NULL if the array is empty or does not have
therequested dimension. To get the total number of array elements across all dimensions, use
<function>cardinality</>.
If we did that, we should probably also add the "or NULL if the array
is empty or does not have the requested dimension" clause to the
array_upper and array_lower docs, and "or NULL if the array is empty"
to the array_dims and array_ndims docs.
That might seem overly pedantic, but it's quite annoying when API
documentation doesn't fully specify the behaviour, and you're forced
to use trial-and-error to find out how the functions behave.
Regards,
Dean