Get records where json column key is null

前端 未结 2 1014
名媛妹妹
名媛妹妹 2020-12-10 00:58

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.

2条回答
  •  时光说笑
    2020-12-10 01:38

    You need to use the ->> operator for that:

    select *
    from users
    where (details->>'email') is not null
    

    Because the -> operator returns 'null'::json (and not sql NULL) if the key is exists but with a json null value.

    http://sqlfiddle.com/#!15/76ec4/2

提交回复
热议问题