MonetDB/pymonetdb

Add support for where in params

Closed this issue · 4 comments

I could not find any way to use pymonetdb with a list of ids for where in.
ids = 1,2
cursor.execute('SELECT*FROM raw.bla WHERE "ID" in %s', ids)

I already tried data, list and tuples, but none of them works.
Always "this type is not supported".

that is not how the API works. It is probably best to make a string of your list and then use it.

This should work:

ids = 1, 2
cursor.execute("select * from image where id in (%s)" % ",".join(str(i) for i in ids))

That solutions seems quite dirty to me, because it would allow sql-injections. By the way: My id list is not static, its dynamic. So it's not practical to bind each param one by one.

You need to check that for yourself. the driver is a low level driver.

If you know a better solution, please feel free to implement it and issue a PR.

Then I will create a pull request in the next days.
Thanks anyway.