Check if a Postgres JSON array contains a string
As of PostgreSQL 9.4, you can use the ? operator: select info->>’name’ from rabbits where (info->’food’)::jsonb ? ‘carrots’; You can even index the ? query on the “food” key if you switch to the jsonb type instead: alter table rabbits alter info type jsonb using info::jsonb; create index on rabbits using gin ((info->’food’)); select info->>’name’ … Read more