[storm] Using In with tuples
Raphael Saint-Pierre
rsaintpi at matrox.com
Tue Feb 16 20:11:53 GMT 2010
Hello,
Using Storm over MySQL, I am trying to find objects with a composite
key; I have a list of key tuples, and wish to filter my objects using
those tuples.
Here is the (simplified) code I am trying to run on a MySQL database:
#--- <snip>---
class Result(Storm):
__storm_table__ = "result"
__storm_primary__ = "id"
id = Int()
time = Float()
class Comparison(Storm):
__storm_table__ = "comparison"
__storm_primary__ = "left_side", "right_side"
left_side = Int()
left_side_ref = Reference(left_side, Result.id)
right_side = Int()
right_side_ref = Reference(right_side, Result.id)
comment = Unicode()
for i in range(1, 6):
r = Result()
r.id = i
store.add(r)
for i in ((1, 2), (3, 4), (1, 4)):
cmp = Comparison()
cmp.left_side = i[0]
cmp.right_side = i[1]
store.add(cmp)
results_to_compare = ((1, 2), (3, 4)) #compare results 1 with 2 and 3
with 4
store.find(Comparison, In((Comparison.left_side, Comparison.right_side),
tuple((r[0], r[1]) for r in
results_to_compare))).count()
#--- </snip> ---
The query that gets executed is the following:
[14:22:54.386000] EXECUTE: u'SELECT COUNT(*) FROM comparison WHERE
comparison.left_side, comparison.right_side IN (?, ?, ?, ?)', (1, 2, 3,
4)
Which obviously raises a ProgrammingError: (1064, "You have an error in
your SQL syntax [...]" because of the malformed WHERE clause.
I was expecting a (tested: working) query like
SELECT COUNT(*) FROM comparison WHERE (comparison.left_side,
comparison.right_side) IN ((?, ?), (?, ?))', (1, 2, 3, 4)
Does Storm provide a mechanism allowing me to do this ?
Thanks in advance,
Raphael Saint-Pierre
More information about the storm
mailing list