Reputation: 936
I have a 2-dimensional int array, and I'd like to get the 2nd element from every array in the 2nd dimension. So for example, I'd like to get 2,4, and 6 from the array literal '{{1,2},{3,4},{5,6}'
. Is this possible? I've searched the docs but I haven't found anything that can do what I want.
Upvotes: 1
Views: 701
Reputation: 36244
unnest(arr[:][2:2])
will give you a table expression for what you want (where arr
is the name of your array column)
If you want to get a 1 dimensional array of those elements, you can use array(select * from unnest(arr[:][2:2]))
(because arr[:][2:2]
is still a 2 dimensional one).
http://rextester.com/VLOJ18858
Upvotes: 2