From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Marko Tiikkaja <marko(at)joh(dot)to> |
Cc: | Florian Pflug <fgp(at)phlo(dot)org>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, 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 00:20:34 |
Message-ID: | CAHyXU0w=-akekvc6gjfq0dYcnEzh8+MmAHva7Fjp0YKLse6KuQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Jan 9, 2014 at 11:08 AM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> On 1/9/14 5:44 PM, Florian Pflug wrote:
>>
>> On Jan9, 2014, at 14:57 , Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>>>
>>> On 19 December 2013 08:05, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>>>
>>>> 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.
>>
>>
>> +1. Anything that complains about arrays whose lower bound isn't 1 really
>> needs a *way* less generic name than array_length().
>
>
> Problem is, if you're operating on an array which could have a lower bound
> that isn't 1, why would you look at the length in the first place? You
> can't access any elements by index, you'd need to look at array_lower().
> You can't iterate over the array by index, you'd need to do array_lower()
> .. array_lower() + array_length(), which doesn't make sense. And then
> there's the myriad of stuff you can do with unnest() without actually having
> to look at the length. Same goes for multi-dimensional arrays: you have
> even less things you can do there with only a length.
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. If you want your code to blow up with non 1
based array, that should be checked in userland I think (perhaps with
a constraint); the server API function should implement as many
reasonable behaviors as possible.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Marko Tiikkaja | 2014-01-10 00:36:33 | Re: array_length(anyarray) |
Previous Message | Peter Geoghegan | 2014-01-09 23:55:16 | Re: Disallow arrays with non-standard lower bounds |