sql - Converting comma separated string to Int list in Postgres -
i trying convert comma seperated string in integer list use in clause.
i have tried cast, ::int
didn't work. appreciate input
example
table | table b id | set_id 2 | 14,16,17 1 | 15,19,20 3 | 21
my query:
select * table a, table b a.id in b.set_id
you need convert string proper integer array if want use join condition.
select * table join table b on a.id = any(string_to_array(b.set_id, ',')::int[]);
but much better solution normalize tables (or at least stores ids in integer array, not varchar column)
Comments
Post a Comment