Reputation: 1366
Postgresql version 12. In a function, want to delete the users with the specific IDs (column "id" bigint). The IDs are passed in as a CSV string(VARCHAR) like this:
'1,2,3'
and the function is like this:
remove_users(in ids varchar)
and in the function want to do:
delete from users where users.id in ids
or
delete from users where users.id = any(array _ids)
how the conversion from csv string to int array be done?
Upvotes: 2
Views: 2048
Reputation: 425198
Use built in array functions:
delete from user
where id any(string_to_array('1,2,3', ','))
Upvotes: 6