How to get current date and time from DB using SQLAlchemy

I need to get what the current date and time for the database I'm connected to is with SQLAlchemy (and not the date and time on which I run the Python code). I saw these functions, but they don't seem to do what they say:

>>> from sqlalchemy import *
>>> print func.current_date()
CURRENT_DATE
>>> print func.current_timestamp()
CURRENT_TIMESTAMP

In addition, it seems that they do not need to be attached to a session or SQLAlchemy engine. This makes no sense...

Thank!

+5
source share
1 answer

I decide the solution: these functions cannot be used the way I used ( print...), but they need to be called inside the code that interacts with the database. For instance:

print select([my_table, func.current_date()]).execute()

. , :

  • type_, , ,
  • bind, SQLAlchemy

:

func.current_date(type_=types.Date, bind=engine1)
func.current_timestamp(type_=types.Time, bind=engine2)

, , , .

+4

All Articles