· 1 min read

How to cast a string of comma separated numbers into an array of integers for Postgres

If you have an string of numbers like

"1,2,3"

and you want to turn it into an array of integers you need to cast it into an integer array type.

"{1,2,3}"::int[]

This is commonly used together when grabbing a set using the ANY clause.

select * from users where id = any('{1,2,3}'::int[])

Comments

Leave a comment