我试图将数据作为多维数组传递,并且我得到了一些看起来很奇怪的行为。具体而言,我试图从二维数组中获取单个元素(因此从我的二维数组中获取一个一维数组),但它并不按照我期望的方式工作。
在以下示例中,2、4和5按照我期望的方式工作,但1和3却没有。
在以下示例中,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)
请问有相关文档吗?目前我有一个工作得足够好的东西,但它很丑陋,我担心它不能实现我接下来想要做的事情。技术上,我得到了一个二维数组,其中一维只有一个元素。我更希望得到一个数组。
我已经阅读过以下内容(其中之一):
- 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
而我并没有看到我所寻找的东西。