获取json列键为null的记录 [英] Get records where json column key is null

查看:43
本文介绍了获取json列键为null的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表个用户,其中有json列详细信息



我想获取所有用户记录,其中details [ email]为null或电子邮件密钥不存在。



这不起作用:

选择用户。* FROM details->'email'不为空的用户;



错误:运算符不存在:json->布尔值

解决方案

使用方括号() 。看起来编译器试图像 details->(电子邮件不为空)那样看它。因此,您可以这样修改它:

  select * 
来自用户
其中(详细信息-> '电子邮件')不为

sql小提琴演示



实际上,以获取 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

sql fiddle demo

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆