If I have a column(lets call it students) in a PostgreSQL db in a JSON/JSONB format like such:
"1":{ "student_id":"1","student_name":"Tim","Pass":true}
"2":{ "student_id":"2","student_name":"Jim","Pass":true}
"3":{ "student_id":"3","student_name":"Pam","Pass":false}
How can I query the students who have passed?
Ideally, I'd write something like SELECT (students->'student_id') FROM table_name WHERE (students->'Pass')=true, but that doesn't work because it has the missing layer of keys i.e "1", "2" and "3". Something that has its logic similar to ...WHERE (students-> *All Keys* ->'Pass')=true is what I'm looking for.
{ "1" : { .... } }? If you remove it the jsonpath you need will be simplified. Otherwise the jsonpath will be more complex. I think using the$.[*].jsonpath is possible.