postgresql - How do I select a subset of an array in Postgres? -


assuming have array in 1 of postgres columns:

> select array[1,2,3,4];    array    -----------  {1,2,3,4}  

how select subset of items array, in general? instance, if want select items x index y index, how grab items in range (x y)?

i'm using postgresql 9.4.

from fine manual:

8.15.3. accessing arrays
[...]
can access arbitrary rectangular slices of array, or subarrays. array slice denoted writing lower-bound:upper-bound 1 or more array dimensions.

for example:

=> select (array[1,2,3,4,5,6])[2:5];    array    -----------  {2,3,4,5} (1 row) 

so slice index x y (inclusive), you'd say:

array_column[x:y] 

Comments