Thanks, Gary! Works perfectly. On Tuesday, March 31, 2015 at 4:27:12 PM UTC-6, Gray Kanarek wrote: > > You want belongs, I think: > > query = db.product.id.belongs((selected_ids)) > > > > On Saturday, March 28, 2015 at 12:14:44 PM UTC-4, gb wrote: >> >> What is the DAL Code to generate a query like this: >> SELECT * FROM product WHERE product.id=1 OR product.id=2 OR product.id=3 >> OR product.id product.id=4 OR product.id=5; >> or even: >> SELECT * FROM product WHERE (product.id=1) OR (product.id=2) OR ( >> product.id=3) OR (product.id=4) OR (product.id=5); >> >> I've tried both the DAL code approaches below and I always end up with >> crazy parentheses nesting which will eventually crash the DB driver e.g. in >> sqlite: <class 'sqlite3.OperationalError'> parser stack overflow >> >> Is there another way to use the DAL, or is my only option to write the >> SQL manually? >> >> db.define_table("product") >> >> selected_ids = [1,2,3,4,5] >> query = [] >> for pid in selected_ids: >> query.append(db.product.id == pid) >> >> query = reduce(lambda a,b:a|b,query) >> #Ouputs this : (((((product.id = 1) OR (product.id = 2)) OR ( >> product.id = 3)) OR (product.id = 4)) OR (product.id = 5)) >> >> >> >> selected_ids = [1,2,3,4,5] >> query = [] >> for pid in selected_ids: >> query |= db.product.id == pid >> >> #I get a bonus parenthesis with this method ((((((product.id = 1) OR >> ) OR (product.id = 2)) OR (product.id = 3)) OR (product.id = 4)) OR ( >> product.id = 5)) >> >
-- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.