On 11/7/06, DNeumann <[EMAIL PROTECTED]> wrote: > > Hello list, > > To build a dynamic where-statement in my script, i looked here for more > info: > http://www.sqlalchemy.org/docs/sqlconstruction.myt#sql_building > > statement = my_table.select() > if id: > statement.append_whereclause(my_table.c.id==id) > if name: > statement.append_whereclause(my_table.c.name==name) > ... > > The where-statement is now generated with the AND-operator. > > now my question: > Is it possible to get OR instead of AND? > Or alternative Solutions? >
Another option that I use quite a lot is to use: query_args = [] if id: query_args.append(my_table.c.id==id) if name: query_args.append(my_table.c.name==name) statement = my_table.select(or_(*query_args)) You can build quite complex queries this way by nesting and_() and or_() in the list. Lee -- Lee McFadden blog: http://www.splee.co.uk work: http://fireflisystems.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---