检查 json 类型列 PostgreSQL 中是否存在字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19422233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:54:36  来源:igfitidea点击:

Check if field exists in json type column PostgreSQL

jsonpostgresql

提问by Alexandru R

How do you check if a jsonfield in Postgres has a certain element?

你如何检查jsonPostgres 中的一个字段是否有某个元素?

I have tried with json->>'attribute' is not nulland doesn't work.

我已经尝试过json->>'attribute' is not null并且不起作用。

回答by Roman Pekar

use ->:

使用->

where (json->'attribute') is not null

回答by Eugen Konkov

While thisworks. It is better to use special operator ?:

虽然有效。最好使用特殊运算符?

WHERE your_column_name::jsonb ? 'attribute'

NOTE: Only for jsonbtype.

注意:仅适用于jsonb类型。