问题
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