How to check if json list has a value in it?

131 Views Asked by At

I have a field with JSON files like this:

"{\"names\":[\"James\",\"Bob\",\"Kate\",\"Tim\",\"Jerald\",\"Massimo\",\"Drake\",\"Ellen\"],\"country\":[\"Usa\",\"Montenegro\",\"Turkey\",\"Spain\"]}"

I want to get only those rows where this field in the country includes 'USA'. So I tried to write smth like this:

select *
from table
where json_field :: jsonb @> '{"country":"USA"}'::jsonb  == True

However, my interpreter states that message [ERROR: type "jsonb" does not exist] Maybe there is another way how to check for the value in postgres? Also tried this

json_field->'country' @> '"USA"'

But this returns this message [ERROR: operator does not exist: json @> unknown

0

There are 0 best solutions below