[web2py] Re: Strange behavior db( ... and ... and ...) vs. db( ... or ... or ...)
Massimo, could we highlight this issue in the documentation somewhere, and/or show the right way to do a compound query. There's no documentation on this stuff, it's very easy to accidentally do because won't throw a syntax error, and we almost just shipped some production code with 'and' instead of On Thursday, June 18, 2009 11:43:37 AM UTC-4, mdipierro wrote: follow up query1 or query2 IS INVALID SYNTAX query1|query2 IS CORRECT or cannot be overwritten in Python so it is still valid but it does not do what you want. query1 or query2 ALWAYS returns just query1. Massimo On Jun 18, 10:43 am, mdipierro mdipie...@cs.depaul.edu wrote: query1 and query2 IS INVALID SYNTAX query1query2 IS CORRECT and cannot be overwritten in Python so it is still valid but it does not do what you want. query1 and query2 ALWAYS returns just query2. Massimo On Jun 18, 8:58 am, weheh richard_gor...@verizon.net wrote: I'm using web2py 1.64.1. I'm seeing a strange behavior in my query. I'm trying to isolate a record using a compound and clause ... very simple stuff: records = db( (db.x.a == i) and (db.x.b==0) and (db.x.c==None) and ...).select(db.x.ALL) But, it returns a whole bunch of records that have nothing to do with my match criteria. I redid the search with an or clause instead, (don't ask me why I did this 'cause it makes no sense to me): records = db( (db.x.a == i) or (db.x.b==0) or (db.x.c==None) or ...).select(db.x.ALL) and believe it or not, this works fine. I think I'm going nuts! Why should this work? --
[web2py] Re: Strange behavior db( ... and ... and ...) vs. db( ... or ... or ...)
http://web2py.com/books/default/chapter/29/6#Logical-operators Specifically: Due to Python restrictions in overloading and and or operators, these cannot be used in forming queries. The binary operators and | must be used instead. Note that these operators (unlike and and or) have higher precedence than comparison operators, so the extra parentheses in the above examples are mandatory. Did you have something else in mind? Anthony On Saturday, August 11, 2012 8:57:38 PM UTC-4, Yarin wrote: Massimo, could we highlight this issue in the documentation somewhere, and/or show the right way to do a compound query. There's no documentation on this stuff, it's very easy to accidentally do because won't throw a syntax error, and we almost just shipped some production code with 'and' instead of On Thursday, June 18, 2009 11:43:37 AM UTC-4, mdipierro wrote: follow up query1 or query2 IS INVALID SYNTAX query1|query2 IS CORRECT or cannot be overwritten in Python so it is still valid but it does not do what you want. query1 or query2 ALWAYS returns just query1. Massimo On Jun 18, 10:43 am, mdipierro mdipie...@cs.depaul.edu wrote: query1 and query2 IS INVALID SYNTAX query1query2 IS CORRECT and cannot be overwritten in Python so it is still valid but it does not do what you want. query1 and query2 ALWAYS returns just query2. Massimo On Jun 18, 8:58 am, weheh richard_gor...@verizon.net wrote: I'm using web2py 1.64.1. I'm seeing a strange behavior in my query. I'm trying to isolate a record using a compound and clause ... very simple stuff: records = db( (db.x.a == i) and (db.x.b==0) and (db.x.c==None) and ...).select(db.x.ALL) But, it returns a whole bunch of records that have nothing to do with my match criteria. I redid the search with an or clause instead, (don't ask me why I did this 'cause it makes no sense to me): records = db( (db.x.a == i) or (db.x.b==0) or (db.x.c==None) or ...).select(db.x.ALL) and believe it or not, this works fine. I think I'm going nuts! Why should this work? --
Re: [web2py] Re: Strange behavior db( ... and ... and ...) vs. db( ... or ... or ...)
Sorry- I missed that altogether. On Sat, Aug 11, 2012 at 11:25 PM, Anthony abasta...@gmail.com wrote: http://web2py.com/books/default/chapter/29/6#Logical-operators Specifically: Due to Python restrictions in overloading and and or operators, these cannot be used in forming queries. The binary operators and | must be used instead. Note that these operators (unlike and and or) have higher precedence than comparison operators, so the extra parentheses in the above examples are mandatory. Did you have something else in mind? Anthony On Saturday, August 11, 2012 8:57:38 PM UTC-4, Yarin wrote: Massimo, could we highlight this issue in the documentation somewhere, and/or show the right way to do a compound query. There's no documentation on this stuff, it's very easy to accidentally do because won't throw a syntax error, and we almost just shipped some production code with 'and' instead of On Thursday, June 18, 2009 11:43:37 AM UTC-4, mdipierro wrote: follow up query1 or query2 IS INVALID SYNTAX query1|query2 IS CORRECT or cannot be overwritten in Python so it is still valid but it does not do what you want. query1 or query2 ALWAYS returns just query1. Massimo On Jun 18, 10:43 am, mdipierro mdipie...@cs.depaul.edu wrote: query1 and query2 IS INVALID SYNTAX query1query2 IS CORRECT and cannot be overwritten in Python so it is still valid but it does not do what you want. query1 and query2 ALWAYS returns just query2. Massimo On Jun 18, 8:58 am, weheh richard_gor...@verizon.net wrote: I'm using web2py 1.64.1. I'm seeing a strange behavior in my query. I'm trying to isolate a record using a compound and clause ... very simple stuff: records = db( (db.x.a == i) and (db.x.b==0) and (db.x.c==None) and ...).select(db.x.ALL) But, it returns a whole bunch of records that have nothing to do with my match criteria. I redid the search with an or clause instead, (don't ask me why I did this 'cause it makes no sense to me): records = db( (db.x.a == i) or (db.x.b==0) or (db.x.c==None) or ...).select(db.x.ALL) and believe it or not, this works fine. I think I'm going nuts! Why should this work? -- --