获取json列键为null的记录 [英] Get records where json column key is null
问题描述
我有表个用户
,其中有json列详细信息
。
我想获取所有用户记录,其中details [ email]为null或电子邮件密钥不存在。
这不起作用:
选择用户。* FROM details->'email'不为空的用户;
错误:运算符不存在:json->布尔值
使用方括号()
。看起来编译器试图像 details->(电子邮件不为空)
那样看它。因此,您可以这样修改它:
select *
来自用户
其中(详细信息-> '电子邮件')不为
实际上,以获取 details [ email]为null或电子邮件密钥不存在的记录,您可以使用以下查询:
从用户
中选择*
,其中(details->>'email')为空
,如此答案所述。
I have table users
with json column details
.
I want to fetch all user records where details["email"] is null or email key doesn't exist.
This doesn't work:
SELECT users.* FROM users where details->'email' IS NOT NULL;
ERROR: operator does not exist: json -> boolean
use brackets ()
. Looks like compiler tries to see it like details->('email' IS NOT NULL)
. So you can fix it like this:
select *
from users
where (details->'email') is not null
actually, to get records where details["email"] is null or email key doesn't exist, you can use this query:
select *
from users
where (details->>'email') is null
as described in this answer.
这篇关于获取json列键为null的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!