How to unnest nested arrays

From: Guyren Howe <guyren(at)gmail(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: How to unnest nested arrays
Date: 2020-04-07 01:11:49
Message-ID: 9BFD1A82-0B06-4B57-A5F4-8525E122B12B@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Consider this:

select (array[array[1, 2], array[3, 4]])[i:i]
from generate_subscripts(array[array[1, 2], array[3, 4]], 1) i

which produces:

{{1,2}}
{{3,4}}

I expect and want, from that source:

{1, 2}
{3, 4}

These don’t work:

select (array[array[1, 2], array[3, 4]])[i:i][:]
{{1,2}}
{{3,4}}

select (array[array[1, 2], array[3, 4]])[i:i][1:1]
{{1}}
{{3}}

Also: could we _please_ get a version of unnest that doesn’t explode any number of dimensions into 1?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message AC Gomez 2020-04-07 02:21:24 extract property value from set of json arrays
Previous Message Devrim Gündüz 2020-04-06 23:43:45 Re: Cstore_fdw issue.