Hello.
I'm unable to figure out how to use mysqldb (actually, dbabi) to write an
"in" query.
For instance, suppose my table looks like this:
Employee(
id int not null primary key,
name varchar(32) not null)
);
Suppose I have a list of ids, I would write sql such as
'select * from Employee where id in (id1, id2, id3)' and this would work
even if there was only one id, say, 'select * from Employee where id in
(id1)'
How should I do this in MySQLdb? It seems that I need to handle single entry
list differently from a list with multiple elements? i.e., this code below
works:
ids = [1, 2, 3]
if len(ids) > 1:
cur.execute('select * from Employee where id in %s', tuple(ids))
else:
cur.execute('select * from Employee where id = %s', ids[0])
but it doesn't seem right. What's the correct way to run this query?
thanks,
Vijay
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers