Postgresql版本12。在一个函数中,想要删除具有特定ID的用户(列“id”bigint)。 ID 作为 CSV 字符串 (VARCHAR) 传入,如下所示:
'1,2,3'
函数如下:
remove_users(in ids varchar)
并在函数中想做:
delete from users where users.id in ids
或
delete from users where users.id = any(array _ids)
如何将 csv 字符串转换为 int 数组?
最佳答案
使用内置数组函数:
delete from user
where id any(string_to_array('1,2,3', ','))
关于Postgresql,将 CSV 字符串转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70658944/