I want to perform an SQL query that is logically equivalent to the following:
DELETE FROM pond_pairs
WHERE
((pond1 = 12) AND (pond2 = 233)) OR
((pond1 = 12) AND (pond2 = 234)) OR
((pond1 = 12) AND (pond2 = 8)) OR
((pond1 = 13) AND (pond2 = 6547)) OR
((pond1 = 13879) AND (pond2 = 6))
I will have hundreds of thousands pond1
-pond2
pairs. I have an index on (pond1, pond2)
.
My limited SQL knowledge came up with several approaches:
- Run the whole query as is.
- Batch the query up into smaller queries with
n
WHERE
conditions - Save the
pond1
-pond2
pairs into a new table, and do a subquery in theWHERE
clause to identify - Convert the python logic which identifies rows to delete into a stored procedure. Note that I am unfamiliar with programming stored procedures and thus this would probably involve a steep learning curve.
I am using postgres if that is relevant.