Il giorno sab, 29/12/2007 alle 11.37 +0100, Harald Armin Massa ha
scritto:
> Joerg,
>
> > maybe this is obvious, but I don't know how to execute a query like:
> > select * from mytable where id in (1,2,3)
> > from python. The difficult part is the set in the where clause, the "in
> > (a,b,c,d, ...)"
>
>
> WHICH database are you talking about?
>
> With Oracle, you are on your own, that is, you have to do stringmagic
> to create the SQL.
>
> With PostgreSQL and PSYCOPG2 you can use lists:
>
> cs.execute("select * from s2e where element = any (%(what)s)",
> dict(what=[1,2,3]))
>
> using PostgreSQL arrays and the "any" function.
psycopg2 supports direct conversion of tuples to IN clauses, doing
quoting on the arguments. Just do:
cs.execute("select * from s2e where element IN %(what)s",
{'what': (1,2,3)})
federico
--
Federico Di Gregorio http://people.initd.org/fog
Debian GNU/Linux Developer [EMAIL PROTECTED]
INIT.D Developer [EMAIL PROTECTED]
If a process is potentially good, but 90%+ of the time smart and
well-intentioned people screw it up, then it's a bad process.
-- Steve Yegge
signature.asc
Description: Questa รจ una parte del messaggio firmata digitalmente
_______________________________________________ DB-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/db-sig
