From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | Marko Tiikkaja <marko(at)joh(dot)to> |
Cc: | Merlin Moncure <mmoncure(at)gmail(dot)com>, Florian Pflug <fgp(at)phlo(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>, PostGreSql hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: array_length(anyarray) |
Date: | 2014-01-10 08:04:07 |
Message-ID: | CAEZATCWEm6Ej8a7_Zu4XbtBq0kWrQvBhz=x5Fn+iB11+sAL96w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 10 January 2014 00:36, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> On 1/10/14, 1:20 AM, Merlin Moncure wrote:
>>
>> I'm piling on: it's not clear at all to me why you've special cased
>> this to lower_bound=1. First of all, there are other reasons to check
>> length than iteration.
>
Yes, I agree. A length function that returned 0 for empty arrays would
be far from useless.
>
> Can you point me to some examples?
>
The example I see all the time is code like
if array_length(nodes, 1) < 5 then
... do something ...
then you realise (or not as the case may be) that this doesn't work
for empty arrays, and have to remember to wrap it in a coalesce call.
Simply being able to write
if cardinality(nodes) < 5 then
... do something ...
is not just shorter, easier to type and easier to read, it is far less
likely to be the source of subtle bugs.
Regards,
Dean
From | Date | Subject | |
---|---|---|---|
Next Message | David Rowley | 2014-01-10 08:12:52 | Re: [PATCH] Negative Transition Aggregate Functions (WIP) |
Previous Message | Dean Rasheed | 2014-01-10 07:57:45 | Re: WIP patch (v2) for updatable security barrier views |