The following bug has been logged on the website:
Bug reference: 13745
Logged by: Duncan Gillis
Email address: duncanmgillis@gmail.com
PostgreSQL version: 9.4.4
Operating system: Ubuntu 13.04; Ubuntu 14.04
Description:
With "arr" being an array of some composite type, "UNNEST(arr) WITH
ORDINALITY _(rec, idx)" suprisingly will populate "rec" and "idx" with the
first two elements from each record in array, rather than the entire record
followed by the ordinality of that record.
This seems inconsistent with how the aliasing behaviour works with
subqueries. It also gets very tedious if you need to unpack a composite type
with lots of fields only to have to put it together again in the SELECT
clause:
SELECT ROW(col1, col2, ..., colN)::some_table, row_idx
FROM UNNEST(array_of_rows) WITH ORDINALITY _(col1, col2, ..., colN,
row_idx)