I've copied this from the bottom of another thread.
The DAL gives different SQL when a query is provided in string format. Is this a bug, or should I not expect this to work? See the example below, the first SQL works, the second SQL raises an error. >>>from gluon.dal import Query >>>query = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & >>>(db.comment.page_id == db.webpage.id) >>>query_as_string = str(query) >>>query_from_string = Query(db, query_as_string) >>>print db(query)._select(db.comment.body) SELECT comment.body FROM comment, webpage WHERE (((comment.id > 0) AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)); >>>print db(query_from_string)._select(db.comment.body) SELECT comment.body FROM comment WHERE ((((comment.id > 0) AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id))); Why do this? If the were possible it would enable you to easily save a query in the session. For example: ==Controller 1== query1 = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & (db.comment.page_id == db.webpage.id) session.query = str(query1) ==Controller 2== from gluon.dal import Query query2 = Query(db, session.query) This does NOT work because the DAL gives different SQL for query1 and query2.