sql - How to retrieve all the rows in postgres where values of a jsonb key is greater then an int value? -
i'm new postgres, if newbie question, please redirect me. i'm trying retrieve rows value greater 0.
this table test
.
id | value ----------- 1 | {'a':1, 'b':2} 2 | {'a':0, 'b':2} 3 | {'a':1, 'b':1} 4 | {'a':0, 'b':0} 5 | {'a':3, 'b':1} 6 | {'a':0, 'b':2}
i have attempted
select * test value --> 'a' > 0;
but didn't work. got
error: argument of must type boolean, not type jsonb
--
denotes comment, after ignored. query effectively:
select * test value
which makes error you're getting quite clear. seems meant use ->>
operator extract element jsonb column. note, however, return text value, , you'd need convert int yourself:
select * test (value->>'a')::int > 0
Comments
Post a Comment