As a developer using Python, I want to be able to hand a
list
to an SQL statement with a WHERE id IN
(…)
clause, and it should do the right thing.
Well, that is not how it started, because it was asked on the internal no-work-channel, so it kind of escalated more.
The original question was:
Dev> Why is it 2021, and SQL prepared statements still can’t deal with IN? Or have I missed some exciting development?
After a quick detour through Java (which we won’t discuss any further in this article), we established that this was a Python problem in this particular instance. And we touched on several other interesting things on our way.
But first, the solution:
#! /usr/bin/env python3
import click
import MySQLdb
import MySQLdb.cursors
class …
[Read more]