Home > Mobile >  Postgresql, convert a CSV string into an array
Postgresql, convert a CSV string into an array

Time:01-11

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?

CodePudding user response:

Use built in array functions:

delete from user
where id any(string_to_array('1,2,3', ','))
  •  Tags:  
  • Related