简体   繁体   English

UNNEST 的订购保证

[英]Ordering guarantees on UNNEST

I am a bit confused around the ordering guarantees of UNNEST(some_array)) .我对UNNEST(some_array))的排序保证有点困惑。 I have read different posts on SO where it is mentioned that Postgres does not guarantee that the order of the input and output will be the same.我在 SO 上阅读了不同的帖子,其中提到 Postgres 不保证输入和 output 的顺序相同。

For example, on this query select unnest(array[1, 2, 3]), unnest(array[4, 5, 6]);例如,在这个查询select unnest(array[1, 2, 3]), unnest(array[4, 5, 6]); The output is: output 是:

orestis=# select unnest(array[1, 2, 3]), unnest(array[4, 5, 6]);
 unnest | unnest
--------+--------
      1 |      4
      2 |      5
      3 |      6
(3 rows)

Is this, also, a possible outcome?:这也是一种可能的结果吗?

orestis=# select unnest(array[1, 2, 3]), unnest(array[4, 5, 6]);
 unnest | unnest
--------+--------
      1 |      5
      2 |      4
      3 |      6
(3 rows)

Interesting.有趣的。 The documentation explains:文档解释说:

The array's elements are read out in storage order.数组的元素按存储顺序读出。

This would imply that the two are aligned.这意味着两者是一致的。

I would instead recommend:我会建议:

select *
from unnest(array[1, 2, 3], array[4, 5, 6]);

The multiple argument form aligns the values.多参数形式对齐值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM