Arrays are an ordered data structure. For array functions that generate new arrays based on existing ones, the documentation isn't clear on whether there's any order that can be assumed for the result.
Functions of interest:
- array_intersect
- array_except
- array_union
- array_distinct
Based on my testing, order seems to be preserved. For the one or more input arrays being operated on, output ordering is based on the input arrays' order, with the first array's order having priority over the second's, etc.
e.g., for array_intersect(array['a', 'b', 'c'], array['d', 'c', 'b']) the result is consistently ['b', 'c'], and not ['c', 'b']. Can this behavior be relied upon?
The following also lack any explicit statement in the docs, but it would be highly surprising if we couldn't assume the order of the returned array is based on the input array(s):
- array_remove
- concat
- combinations
- filter
Arrays are an ordered data structure. For array functions that generate new arrays based on existing ones, the documentation isn't clear on whether there's any order that can be assumed for the result.
Functions of interest:
Based on my testing, order seems to be preserved. For the one or more input arrays being operated on, output ordering is based on the input arrays' order, with the first array's order having priority over the second's, etc.
e.g., for
array_intersect(array['a', 'b', 'c'], array['d', 'c', 'b'])the result is consistently['b', 'c'], and not['c', 'b']. Can this behavior be relied upon?The following also lack any explicit statement in the docs, but it would be highly surprising if we couldn't assume the order of the returned array is based on the input array(s):