我正在尝试将数据作为多维数组传递,而我的行为对我来说似乎很奇怪。具体来说,我试图从二维数组中获取单个元素(因此从我的二维数组中获取一维数组),但它并没有按照我期望的方式工作。
在以下示例中,#2、4 和 5 以我期望的方式工作,但 1 和 3 没有。
db=> select s.col[2] from (select array[[1,2,3],[4,5,6]] as col) s;
col
-----
(1 row)
db=> select s.col[2:2] from (select array[[1,2,3],[4,5,6]] as col) s;
col
-----
{{4,5,6}}
(1 row)
db=> select array[s.col[2]] from (select array[[1,2,3],[4,5,6]] as col) s;
array
--------
{NULL}
(1 row)
db=> select array[s.col[2:2]] from (select array[[1,2,3],[4,5,6]] as col) s;
array
-------------
{{{4,5,6}}}
(1 row)
db=> select s.col[2][1] from (select array[[1,2,3],[4,5,6]] as col) s;
col
-----
4
(1 row)
有这方面的文档吗?我现在有一些对我来说运行良好的东西,但它很丑,我担心它不会做我接下来想做的事情。从技术上讲,我得到一个二维数组,其中 1 维只有 1 个元素。我宁愿只得到一个数组。
我读过(除其他外):
- http://www.postgresql.org/docs/9.1/static/arrays.html
- http://www.postgresql.org/docs/9.1/static/functions-array.html
- http://www.postgresql.org/docs/9.1/static/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS
而且我只是没有看到我在寻找什么。