【发布时间】:2015-01-22 06:16:22
【问题描述】:
其中data是JSONB列,我想检查key是否存在,一般我用:
SELECT id FROM users WHERE length(data->>'fingerprint_id') IS NULL;
有没有更好/更短的方法来做到这一点?因为其他替代方案给出了不正确的结果:
> SELECT id FROM users WHERE data->>'fingerprint_id' IS NULL;
ERROR: operator does not exist: jsonb ->> boolean
LINE 1: SELECT id FROM users WHERE data->>'fingerprint_id' IS NULL;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
> SELECT id FROM users WHERE data->>'fingerprint_id' = '';
id
----
(0 rows)
【问题讨论】:
标签: postgresql jsonb