Execute Query based on the JSON that stored inside the column

此生再无相见时 提交于 2019-12-11 10:19:54

问题


I am using PostgresSQL database and I have four columns in a table and one of them stores a JSON, for example:

{"a":"1","b":"2","c":"3"}

I want to execute query that returns me all the rows which have c = 3 in that column. How can I achieve this with Hibernate?


回答1:


Use ->> operator:

-- Example data
create table test (id int, js jsonb);
insert into test values 
(1, '{"a":"1","b":"2","c":"3"}'),
(2, '{"a":"1","b":"2","c":"4"}');

--query
select * 
from test
where js->>'c' = '3';

 id |               js               
----+--------------------------------
  1 | {"a": "1", "b": "2", "c": "3"}
(1 row) 


来源:https://stackoverflow.com/questions/33236905/execute-query-based-on-the-json-that-stored-inside-the-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!