Handling standard array structure in postgresSQL

Viewed 35

I have column "session" in table "A" which looks like this

session
[1,3,5,2]
[5,1,3,2]

values in rows saved as VARCHAR, but i want to cast it to array and do some operations on values inside the array

is there a way a to cast those to array? , thank you

1 Answers

You need to replace your brackets [] to braces {} to make it a standard array type. then cast it to int[].

select unnest(replace(replace(session, '[', '{'), ']', '}')::int[])
Related