0

I have a column named people and it's type is JSONB.

Here is the sample data (1 row):

{"addresses": [{"street":"cubuklu", "valid?": "true"} 
               {"street":"beykoz", "valid?":"false"}
               {"street":"kavacik", "valid?": "true"} ]}

I would like to get list of streets that have valid? true value for all rows.

Result:

cubuklu
kavacik
......(data from other rows)

I'm able to list of arrays could not filter values tho.

1 Answer 1

1

You need to unnest the array and then filter on the result:

select adr.address ->> 'street'
from the_table t
  cross join jsonb_array_elements(t.people -> 'addresses') as adr(address)
where adr.address ->> 'valid?' = 'true'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.