如何知道hstore数据类型是否具有特定密钥



我有一个表,它有一个数据类型为hstore的列,现在我想知道哪些行中没有特定的键。我尝试的查询是:

select * from user_offer where not outputs ? 'target_term' and rule_id = 221 limit 10

备注输出为hstore列,target_term为键。

如果键target_term不存在,则输出->'target_term'返回NULL,因此您可以尝试以下查询:

SELECT * FROM user_offer WHERE (outputs -> 'target_term'::TEXT) IS NULL AND rule_id = 221 LIMIT 10;

这将选择列输出没有键target_term的行。

另请参阅http://www.postgresql.org/docs/9.4/static/hstore.html

最新更新