Re: array_length(anyarray)

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, 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-11 14:24:00
Message-ID: 646139A2-20F7-4F32-AACB-20CCEE1D135B@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jan10, 2014, at 15:10 , Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Fri, Jan 10, 2014 at 6:00 AM, Florian Pflug <fgp(at)phlo(dot)org> wrote:
>> On Jan10, 2014, at 11:00 , Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>>> On Fri, Jan 10, 2014 at 3:52 AM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
>>>> On 1/10/14, 10:41 AM, Merlin Moncure wrote:
>>>>>
>>>>> 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'.
>>>>
>>>>
>>>> So unnest_dims('{{1,2},{3,4}}'::int[]) would return VALUES (1,
>>>> '{1,2}'::int[]), (2, '{3,4}'::int[])? If so, then yes, that's a
>>>> functionality I've considered us to have been missing for a long time.
>>>
>>> not quite. it returns int[], anyelement: so, using your example, you'd get:
>>>
>>> [1,1], 1
>>> [1,2], 2
>>> [2,1], 3
>>> [2,2], 4
>>
>> Now that we have WITH ORDINALITY, it'd be sufficient to have a
>> variant of array_dims() that returns int[][] instead of text, say
>> array_dimsarray(). Your unnest_dims could then be written as
>>
>> unnest(array_dimsarray(array)) with ordinality
>
> hm, not quite following that. maybe an example?
>
> my issue with 'WITH ORDINALITY' (while it's pretty neat) is that it
> doesn't give you the dimension coordinate of each datum so you can't
> really use it to slice. with unnest_dims(), you an slice, say via:

Sorry, I misunderstood what you were proposing. I though you intended
unnest_dims to returns one row per dimension, containing the index and
bounds of that dimension. And yeah, that fact your your mail showed
unnest_dims returning *4* rows for a *2*-dimensional array should have
tipped me off.

best regards,
Florian Pflug

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Adrian Klaver 2014-01-11 14:43:16 Re: pg_upgrade & tablespaces
Previous Message Simon Riggs 2014-01-11 12:25:12 Re: Simple improvements to freespace allocation