3

Let me keep it simple , Is there a mysql function unix_timestamp(datetime) in SQLAlchemy ? or is there any workaround ?

1 Answer 1

5

SQLAlchemy has support for arbitrary SQL functions. See http://www.sqlalchemy.org/docs/core/tutorial.html#functions.

from sqlalchemy.sql import func

for row in conn.execute(select([func.unix_timestamp("a_datetime_column")], ...)):
    # ...
Sign up to request clarification or add additional context in comments.

3 Comments

can it be used for other database engines ?
No. func.NNN is a reference to a SQL function with name NNN, The db engine must support NNN. Certain function names are known by SQLAlchemy and are given special treatment, see sqlalchemy.org/docs/core/tutorial.html#functions and sqlalchemy.org/docs/core/…
How to apply this to: analys = Analyzes.query.filter_by(id=id).first()?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.