From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | David Fetter <david(at)fetter(dot)org>, Marko Tiikkaja <marko(at)joh(dot)to>, PostGreSql hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: array_length(anyarray) |
Date: | 2014-01-09 13:57:58 |
Message-ID: | CAEZATCWKyM0qpi+kimKr1s5MNaoT07j_t6Qe7VNWEx8k=AQfqA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 19 December 2013 08:05, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>
>
> 2013/12/19 David Fetter <david(at)fetter(dot)org>
>>
>> On Wed, Dec 18, 2013 at 09:27:54PM +0100, Marko Tiikkaja wrote:
>> > Hi,
>> >
>> > Attached is a patch to add support for array_length(anyarray), which
>> > only works for one-dimensional arrays, returns 0 for empty arrays
>> > and complains if the array's lower bound isn't 1. In other words,
>> > does the right thing when used with the arrays people use 99% of the
>> > time.
>>
>> +1 for adding this.
>
>
> +1
>
I think that having 2 functions called array_length() that each behave
differently for empty arrays would just lead to confusion.
The SQL standard defines a function called cardinality() that returns
the number of elements of a collection (array or multiset), so why
don't we call it that?
> length should be irrelevant to fact so array starts from 1, 0 or anything
> else
Yes, this should just return the number of elements, and 0 for an empty array.
How it should behave for multi-dimensional arrays is less clear, but
I'd argue that it should return the total number of elements, i.e.
cardinality('{{1,2},{3,4}}'::int[][]) = 4. That would make it
consistent with the choices we've already made for unnest() and
ordinality:
- cardinality(foo) = (select count(*) from unnest(foo)).
- unnest with ordinality would always result in ordinals in the range
[1, cardinality].
Regards,
Dean
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2014-01-09 14:12:38 | Re: nested hstore patch |
Previous Message | Stephen Frost | 2014-01-09 13:50:18 | Re: Planning time in explain/explain analyze |