Assume the following posts
table in a Postgresql 9.3 database
|id|name|properties|
--------------------
Where properties
is a JSON column.
An example JSON would be:
{
"comments":[
{
"user_id":1,
"comment":"foo"
},
{
"user_id":2,
"comment":"bar"
},
{
"oddCase":2,
"thisShouldStillWork":true
}
]
}
How can I issue a SELECT statement with an "AND" or "or" WHERE?
So one would be able to:
- Select all the posts where at least user_id 1 OR user_id 2 OR user_id n ... has commented.
- Select all the posts where at least user_id 1 AND user_id 2 AND user_id n ... has commented on.
EDIT: Looks like json_array_elements
with a dynamically generated query will work.