我有一个像这样的 postgresql 数据库:
users
id name companyrestrictions
1 Bill [3, 4]
2 Fred [5, 6]
在这种情况下,每个公司 3
都有一个变量
所以我写了这样一个查询:
SELECT * FROM users WHERE 3 = ANY(users.companyrestrictions)
但我收到以下错误: op ANY/ALL (array) 需要右侧的数组
公司限制是类型jsonb
我做错了什么?
最佳答案
尝试 <@
包括 operator :
<@ Are the left JSON path/value entries contained at the top level within the right JSON value?
SELECT * FROM users WHERE '3' <@ users.companyrestrictions
ANY 只适用于数组
关于sql - PostgreSQL select * 其中列包含数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47239659/