boratutumluer
boratutumluer

Reputation: 1

how to select value in array with index in postgresql?

id list
1 {759-10,1147-7,931-10}
2 {719-10,117-2}

expected

id list1 list2
1 759-10 931-10
2 719-10 117-2

Upvotes: 0

Views: 1659

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269803

If you just want the first and last elements, use array operations:

select id, list[1], list[cardinality(list)]
from t;

Here is a db<>fiddle.

Upvotes: 1

Related Questions