Re: array_length(anyarray)

Поиск
Список
Период
Сортировка
От Dean Rasheed
Тема Re: array_length(anyarray)
Дата
Msg-id CAEZATCWEm6Ej8a7_Zu4XbtBq0kWrQvBhz=x5Fn+iB11+sAL96w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: array_length(anyarray)  (Marko Tiikkaja <marko@joh.to>)
Ответы Re: array_length(anyarray)  (Marko Tiikkaja <marko@joh.to>)
Re: array_length(anyarray)  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-hackers
On 10 January 2014 00:36, Marko Tiikkaja <marko@joh.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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Dean Rasheed
Дата:
Сообщение: Re: WIP patch (v2) for updatable security barrier views
Следующее
От: David Rowley
Дата:
Сообщение: Re: [PATCH] Negative Transition Aggregate Functions (WIP)