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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -