From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Cc: | Marko Tiikkaja <marko(at)joh(dot)to>, 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 09:41:34 |
Message-ID: | CAHyXU0xmqirCzkXDFg2T-5maFtkrqFbsByZzwZNkCpkqAt_RWw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Jan 10, 2014 at 2:04 AM, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
> 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.
right -- exactly. or, 'ORDER BY cardinatility(nodes)', etc etc.
Furthermore, we already have pretty good support for iteration with
arrays via unnest(). What's needed for better iteration support (IMO)
is a function that does what unnest does but returns an array on
indexes (one per dimsension) -- a generalization of the
_pg_expandarray function. Lets' say 'unnest_dims'. 'unnest_dims' is
non-trivial to code in user land while 'array_length' is an extremely
trivial wrapper to array_upper().
cardinality() (which is much better name for the function IMSNHO)
gives a*b*c values say for a 3d array also does something non-trivial
*particularly in the case of offset arrays*.
On Fri, Jan 10, 2014 at 3:36 AM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> I guess what I truly want is a less generic type that's like an array, but always one-dimensional with a lower bound of 1.
Your function would be the only one in the array API that implemented
special behaviors like that. That's suggests to me that the less
generic function belongs in user land, not in the core array API.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Dean Rasheed | 2014-01-10 09:43:51 | Re: [PATCH] Negative Transition Aggregate Functions (WIP) |
Previous Message | Marko Tiikkaja | 2014-01-10 09:36:43 | Re: array_length(anyarray) |