Where is the end of the humain?

sql 如何在大量reference Id中查询是否存在

项目中需要查询用户是否符合范围,首先在查询用户的时候,先绑定用户的链接范围。可以的用户的属性中绑定其范围,类型用 string,分隔符自定义,之后在 sql 查询中需要用到。涉及的技术栈:postgresql,mybatis

可靠性最好的,数量再长,性能都够用:

1
AND id in (select unest(string_to_array(#{variable},',')) ::integer)

可选,以下都不可靠:

1
2
AND (select exists 
(select 1 from regexp_split_to_table(#{variable},',') as val where val::int = id))
1
AND ',' ||#{variable} || ',' like '%,' ||id ||',%'

© 2026 iattachの小站

Elegant theme by Shiro · Made by Acris with ❤️