On Thu, 2008-01-31 at 16:19 -0500, Michael Bayer wrote:
> if you compare from the left to the right, it will work:
> 
> table.c.column >= start_date
> 
> the DateTime type itself is not part of the operation at the python  
> comparison level.

Also, just monkeypatching a timetuple = None onto the types.DateTime
makes it work as well.  I'd think that would be a bit less confusing to
users.

Regards,
Cliff

> On Jan 31, 2008, at 4:02 PM, Cliff Wells 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to