Postgresql,将 CSV 字符串转换为数组

标签 postgresql function

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/

相关文章:

c - 在 C 中的单独函数中打印数组

postgresql - 生成系列 Postgres

sql - PostgreSQL 错误 : relation "products" does not exist

c - 为什么 struct int 值没有被传递到下一个函数?

python-3.x - 无法理解此递归函数的分配和环境用法

c - 如何对函数c中的随机数求和?

python - 与 return 语句一起使用 'elif' 或连续的 'if' 语句更好吗?

postgresql - Kafka Connect JDBC Sink quote.sql.identifiers 不工作

postgresql - JOIN 结果的顺序

postgresql - postgres pgagent 作业状态