2

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?

1

1 Answer 1

6

Use built in array functions:

delete from user
where id any(string_to_array('1,2,3', ','))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.