I have a Python list which looks like this:
[{'id': 5, 'field1': True}, {'id': 6, 'field1': False}]
It's just a list of dictionaries containing key/value pairs. I want to look up rows from a table in a Postgres database that match on id
and differ on field1
.
Say my table looks like:
id field1
-----------
5 True
6 True
Only the second row should be in the result: it matches on id = 6
but differs on field1 = true
Is there any way to achieve this with SQL or would I need to loop through it manually? My use case involves a lot of rows, and this process would be repeated many times, so I'm trying to find the most efficient way to do it.