I am trying to pass data as a multidimensional array, and I am getting behavior that seems strange to me. In particular, I am trying to get one element from a 2-dimensional array (therefore a 1-dimensional array from my 2-dimensional array), and it does not work as I expected.
In the following examples, # 2, 4, and 5 work as I expected, but 1 and 3 do not.
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)
Is there a document on this? I have something that works well enough for me right now, but it's ugly, and I'm worried that he will not do what I want to do next. Technically, I get a 2-dimensional array, where 1 size has only 1 element. I would rather just get an array.
I read (among other things):
, .