Re: Review: UNNEST (and other functions) WITH ORDINALITY - Mailing list pgsql-hackers

From Josh Berkus
Subject Re: Review: UNNEST (and other functions) WITH ORDINALITY
Date
Msg-id 51CA343A.6050808@agliodbs.com
Whole thread Raw
In response to Review: UNNEST (and other functions) WITH ORDINALITY  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: Review: UNNEST (and other functions) WITH ORDINALITY
Re: Review: UNNEST (and other functions) WITH ORDINALITY
List 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



pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: Re: FILTER for aggregates [was Re: Department of Redundancy Department: makeNode(FuncCall) division]
Next
From: Brendan Jurd
Date:
Subject: Re: Kudos for Reviewers -- straw poll