I have a jsonb column in Postgres 9.6 that contains JSON arrays of the following form:
[
{
"courses": { "course-1": { "graduated": false }, "course-5": { "graduated": true } }
},
{
"courses": { "course-6": { "graduated": false } }
}
]
I want to find all of the users who have enrolled in either course-1 or course-12 with a single query. That is, users who have either course-1 or course-12 in the courses object for any of the entries in their jsonb array.
I've tried a bunch of things like the following, which of course doesn't work:
select enrollment_info from users where (enrollment_info @> '["courses" ?| array['course-1', 'course-12']]')
Any suggestions on how to solve this issue? Thanks!