简体   繁体   English

检查jsonb列中是否存在属性

[英]Check if a property exists in a jsonb column

I'm facing a problem filtering rows by property in a jsonb column type. 我面临一个问题,即按jsonb列类型的属性过滤行。

I tried this: 我尝试了这个:

jsonb_column ? 'my_property'

On pgadmin or psql it works well, but over a JDBC driver it throws the error: pgadminpsql它运行良好,但是在JDBC驱动程序上,它将引发错误:

org.hibernate.QueryException: Expected positional parameter count: 3, actual parameters: []

The problem is with the ? 问题出在? operator. 操作员。 So, there're another way to do that? 那么,还有另一种方法吗?

well, after some researches and no one solution to my problem with the "?" 好吧,经过一些研究,没有人能解决我的“?”问题 operator over de JDBC driver, I solved it another way, the function 通过JDBC驱动程序操作符,我用另一种方式解决了该功能

jsonb_object_keys jsonb_object_keys

returns all keys of my json element, and then I filter each one using the <@ operator like: 返回json元素的所有键,然后使用<@运算符过滤每个键,例如:

ARRAY(SELECT jsonb_object_keys(jsonb_column)) <@ '{property1,property2,property3}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM