Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Postgresql, convert a CSV string into an array

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

Use built in array functions:

delete from user
where array_position(string_to_array('1,2,3', ','), id) > 0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading