gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:11:36 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com