Re: Review: UNNEST (and other functions) WITH ORDINALITY

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Review: UNNEST (and other functions) WITH ORDINALITY
Date: 2013-06-26 00:22:18
Message-ID: 51CA343A.6050808@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Folks,

(the below was already discussed on IRC)

Leaving names aside on this patch, I'm wondering about a piece of
functionality I have with the current unnest() and with the
unnest_ordinality()[1] extension: namely, the ability to unnest several
arrays "in parallel" by using unnest() in the target list.

For example, given the table:

lotsarrays (
id serial PK,
arr1 int[],
arr2 numeric[],
arr3 boolean[]
)

I can currently do:

SELECT id,
unnest(arr1) as arr1,
unnest(arr2) as arr2,
unnest(arr3) as arr3
FROM lotsarrays;

... and if arr1, 2 and 3 are exactly the same length, this creates a
coordinated dataset. I can even use the unnest_ordinality() extension
function to get the ordinality of this combined dataset:

SELECT id,
(unnest_ordinality(arr1)).element_number as array_index,
unnest(arr1) as arr1,
unnest(arr2) as arr2,
unnest(arr3) as arr3
FROM lotsarrays;

There are reasons why this will be complicated to implement WITH
ORDINALITY; DF, Andrew and I discussed them on IRC. So allowing WITH
ORDINALITY in the target list is a TODO, either for later in 9.4
development, or for 9.5.

So, this isn't stopping the patch; I just want a TODO for "implement
WITH ORDINALITY in the target list for SRFs".

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brendan Jurd 2013-06-26 00:40:17 Re: Kudos for Reviewers -- straw poll
Previous Message Josh Berkus 2013-06-26 00:01:39 Re: FILTER for aggregates [was Re: Department of Redundancy Department: makeNode(FuncCall) division]