You can shorten it a little by having the db do the date operation: History.c.ts_created > func.now() - '90 minutes'
On 1/11/07, Chris Shenton <[EMAIL PROTECTED]> wrote: > > I've got a bunch of history and other timestamped information I will > need to query against. The columns are created with type DateTime and > get set upon row creation: > > history_table = Table( > 'history', metadata, > Column('history_id', Integer, primary_key=True), > Column('system_id', Integer, > ForeignKey('system.system_id'), nullable=False), > Column('ts_created', DateTime, > default=func.current_timestamp()), > Column('ts_updated', DateTime, > onupdate=func.current_timestamp()), > ) > > I'm going to want to do lots of queries on this 'history' table for a > specific 'system_id' and a 'ts_created' within some duration in the > past -- like 5 or 60 minutes. > > It's taken me a while to figure out the SQLAlchemy syntax to make this > work and it seems a bit verbose: > > session.query(History).select(and_(History.c.system_id==42, > History.c.ts_created > > datetime.datetime.now() - datetime.timedelta(minutes=90))) > > Is there a better, more concise way to say this? > > Thanks. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---