I found strange behavior.
I have a model:
class User(Base):
__tablename__ = 'test_user'
id = Column(Integer, primary_key=True)
timeout = Column(Integer)
last_receive_time = Column(TIMESTAMP)
I have a next script:
# run several times
session.add( User( timeout=1, last_receive_time=datetime.datetime.now() ))
session.commit()
query = session.query(User)\
.from_statement(text("""
SELECT *
FROM test_user
WHERE (last_receive_time + INTERVAL '1 second' * timeout) < NOW() """))
print('amount records using NOW() = %s' % len(query.all()))
This script always returns:
amount records using NOW() = 0
But if we run raw sql(without alchemy) the result will be correct(not *0*).
*Env:* Python 3.6.1, SQLAlchemy 1.2.8, psql (PostgreSQL) 10.4 (Debian
10.4-2.pgdg90+1)
Also *I found
<https://stackoverflow.com/questions/50989199/sqlalchemy-from-statement-now>*
that with *params()* the query is working fine.
Is it correct?
Thank you.
--
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.