I also like to use escaped identifiers in cases like this: sql = "select tID,tNote from %s where %s = %%s" % ("tmp","tID") cursor.execute(sql,1) should work fine.