Hello Cliff, I'm using datetime queries to filter results based on a date interval. You could try using the between() construct to get the records you desire. Something like this:
q = q.filter(between(Post.c.post_date,start_date,end_date)) Specifying the query this way works for me. Hope that helps. Regards, Rooju On Jan 31, 2008 2:02 PM, Cliff Wells <[EMAIL PROTECTED]> wrote: > > This appears to be a bug in SA 0.4.2p3: > > > >From the datetime docs: > ''' > Note: In order to stop comparison from falling back to the default > scheme of comparing object addresses, datetime comparison normally > raises TypeError if the other comparand isn't also a datetime object. > However, NotImplemented is returned instead if the other comparand has a > timetuple attribute. > ''' > > It appears to me (although I need to do some more digging to verify) > that types.DateTime lacks a timetuple attribute, so a TypeError is > getting raised rather than returning NotImplemented. > > Regards, > Cliff > > On Thu, 2008-01-31 at 12:41 -0800, Cliff Wells wrote: > > I'm using SA 0.4 and Pylons 0.9.6. > > > > > > Why would this: > > > > def by_date ( self, year, month, day ): > > post_q = Session.query ( Post ) > > start_date = datetime ( int ( year ) , int ( month ), int ( day ) ) > > end_date = start_date + timedelta ( 1 ) > > c.post_index = post_q.filter ( > > and_ ( [ start_date <= Post.c.post_date, > > end_date > Post.c.post_date ] ) > > ).all ( ) > > > > > > Give me this traceback: > > ... > > and_ ( [ start_date <= Post.c.post_date, > > TypeError: can't compare datetime.datetime to Column > > > > > > I've also tried a couple variations such as > > > > c.post_index = post_q.filter ( > > start_date <= Post.post_date, > > end_date > Post.post_date > > ).all ( ) > > > > and using post_table.c.post_date, etc. All of which give me the same > > error or > > > > TypeError: can't compare datetime.datetime to InstrumentedAttribute > > > > I've only seen a couple examples on the ML of doing selects with > > datetime objects and there isn't much in the way of documentation that > > I've seen (unless I'm blind or too dense to see it). > > > > Thanks, > > Cliff > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---