[DB-SIG] Parameter substitution and "IN" operator
Eric Brunson
brunson at brunson.com
Mon Mar 17 19:30:22 CET 2008
Has there been any discussion of supporting lists or tuples as
parameters to the "IN" operator?
I'd like to be able to do something to the effect of:
curs.execute( "select * from mytable where col1 = %s and col2 in (%s)",
( 'firstval', ('list', 'of', 'vals') )
Or perhaps:
curs.execute( "select * from mytable where col1 = %s and col2 in %s",
( 'firstval', ('list', 'of', 'vals') )
And have the module include the parens.
It seems to almost work sometimes:
c.execute( 'select * from gateway where code in %s', ( ( 1, 2 ), ) )
print c._executed
Yields:
select * from gateway where code in ('1', '2')
but
c.execute( 'select * from gateway where code in %s', ( ( 'cys', 'syr' ), ) )
print c._executed
yields:
select * from gateway where code in ("'cys'", "'syr'")
Besides, I think it's just a side effect of the string representations
of the tuple and not a planned feature.
I know how to build a string with the correct number of placeholders for
my "IN" list, but I think it would be a nice feature of the API to
handle it for the the user.
Thanks,
e.
More information about the DB-SIG
mailing list