检查json类型列PostgreSQL中是否存在字段

时间:2013-10-17 08:58:23

标签: json postgresql

如何检查Postgres中的json字段是否包含某个元素?

我尝试使用json->>'attribute' is not null但无效。

2 个答案:

答案 0 :(得分:48)

使用->

where (json->'attribute') is not null

答案 1 :(得分:4)

虽然this有效。最好使用特殊运算符?

WHERE your_column_name::jsonb ? 'attribute'

注意:仅适用于jsonb类型。