Ah I see,  I was using q = 
s.query(A.is_current_address).filter(A.is_current_address==True), just 
using A.is_current_address produces the same results you have.  Thanks!

On Thursday, November 30, 2017 at 12:49:37 PM UTC-5, Mike Bayer wrote:
>
> On Thu, Nov 30, 2017 at 10:31 AM, Kevin Foley <[email protected] 
> <javascript:>> wrote: 
> > I created a Boolean attribute for an Oracle table that checks if an 
> address 
> > is the customer's current address. 
> > 
> > @is_current_address.expression 
> > def is_current_address(cls): 
> >         return and_(cls.eff_date <= func.current_date(), cls.term_date 
> >= 
> > func.current_date()) 
> > 
> > When I try to run a query with this it generates the following where 
> clause: 
> > 
> > WHERE (addresses.eff_date <= CURRENT_DATE AND addresses.term_date >= 
> > CURRENT_DATE) = 1 
>
>
> can you show me the "try to run a query" part, because that expression 
> alone would not be doing the "= 1" thing you are describing.   it 
> would do that if it were being interpreted in some boolean context 
> like "expr == True" or something like that. 
>
> Here's an MCVE: 
>
> from sqlalchemy import * 
> from sqlalchemy.orm import * 
> from sqlalchemy.ext.declarative import declarative_base 
> from sqlalchemy.ext.hybrid import hybrid_property 
> import datetime 
> from sqlalchemy.dialects import oracle 
>
> Base = declarative_base() 
>
>
> class A(Base): 
>     __tablename__ = 'a' 
>     id = Column(Integer, primary_key=True) 
>     eff_date = Column(DateTime) 
>     term_date = Column(DateTime) 
>
>     @hybrid_property 
>     def is_current_address(self): 
>         return self.eff_date <= datetime.datetime.now() and \ 
>             self.term_date >= datetime.datetime.now() 
>
>     @is_current_address.expression 
>     def is_current_address(cls): 
>         return and_( 
>             cls.eff_date <= func.current_date(), 
>             cls.term_date >= func.current_date()) 
>
> s = Session() 
>
> q = s.query(A.is_current_address).filter(A.is_current_address) 
>
> print q.statement.compile(dialect=oracle.dialect()) 
>
>
> output: 
>
> SELECT a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE AS 
> is_current_address 
> FROM a 
> WHERE a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE 
>
> tried it back to 1.0.x doesn't render an =1 
>
>
>
>
>
>
> > 
> > and generates the Oracle  error: 
> > 
> >> ORA-00933: SQL command not properly ended 
> > 
> > 
> > I believe this type of expression isn't supported in Oracle, however 
> > manually removing the "= 1" from the clause makes the query work.  Is 
> there 
> > a different approach I need to take to make sure this is handled 
> properly? 
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to