I have batch_table table, which contain batchid type of serial int and data type of JSONB, I indexed data column using GIN,
batchid | data
---------------------------------------------
1 | [{"year":2000,"productid":[21, 32, 5]}]
2 | [{"year":2001,"productid":[21, 39, 5]},{"year":2000,"productid":[1, 25, 5]}]
3 | NULL
4. | [{"year": 2000,"productid":[5]}
Now I want to get batchid by using following requirements
1. year = 2000 & productid= 5
2. year = 2000 & productid= (21 or 5)
3. year = 2000 & productid= (21 & 5)
and I tried this
SELECT batchid FROM batch_table WHERE (data->>'year')::int = 2000 AND (data->>'productid')::int = 5;
with AND & OR for other queries