[DB-SIG] comparing with lists via cx_Oracle
Harald Armin Massa
haraldarminmassa at gmail.com
Mon Jan 8 19:01:55 CET 2007
Sometimes I have to get additional data for a set of ids, the usual select of
select whatever from sometable where id in (1,2,3,4,5)
Next level is, [1,2,3,4,5] is a Collection in Python (List, Tuple, Set)
to transcribe it as
cs.execute("select whatever from sometable where id in (%(pyeles)s)",
dict(pyeles=[1,2,3,4,5]))
obviously does not work.
within PostgreSQL and psycopg2 I can write:
cs.execute("""select name from kundentable
where id_p = any(%(ids)s)""",
dict(ids=[8718, 27339, 108509463, 9113, 14951]))
which gets translated to
cs.query
'select name from kundentable
where id_p = any(ARRAY[8718, 27339, 108509463, 9113, 14951])'
and yields the appropriate result.
oracle supports something similar with
select name from kundentable where id_p=any(8718, 27339, 108509463, 9113, 14951)
BUT... how can I get that list of ID_S from Python to Oracle via cx_Oracle?
Harald
--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Reinsburgstraße 202b
70197 Stuttgart
0173/9409607
-
Python: the only language with more web frameworks than keywords.
More information about the DB-SIG
mailing list