Skip to content
Advertisement

Finding a single element in postgres json array

I have a table that has a Json typed column and I am trying query that table based of values that are contained in that json column.

Here is the relevant DDL:

Here is what a roles value would look like:

I want to be able to perform a query like this:

So I’ve tried this:

And it is giving me this error:

Advertisement

Answer

The operator @> works on jsonb arguments. Cast the column to jsonb:

Update. There is no operator to search in a json array for any of multiple values. You can use the function json_array_elements_text(), e.g.:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement