postgresql - Ordered result from unnest() function -
there guarantee function unnest() return values in these order, how located?
that is, exmple this:
arr (integer[]) --------------- {{3,5},{33,3}} this query:
select unnest(arr) "table"
always return
3 5 33 3 ?
or may result ordered differently, array elements ordered?
here's helpful link unnest result order vs array data.
here's assumption:
an unnest() scan array in-order, once embed in large query ordering no longer guaranteed.
quote thread:
unnest() returns output in same order input. since array ordered returned in same output order unnest. however, since unnest() returns single column (though possibly of composite type) cannot provide row number in output in order maintain same order elsewhere in query necessary use "row_number() on (...)" on output of unnest() - , before joining other unnest calls or tables - before supplying rest of query. "with ordinality" functionality proposed 9.4 cause unnest() [and other] function output additional column along usual output. is, pretty such, usability enhancement makes easier can done today using cte/with and/or sub-queries.
another useful links:
Comments
Post a Comment