Set timezone when using pandas read_sql and SQLAlchemy engine

Viewed 47

While using pymysql driver, we are first executing set time_zone= <timezone> on cursor and then the query. We want to use same time zone while using read_sql and sqlalchemy_engine while selecting data as dataframe. Is it possible to set the timezone while using pd.read_sql? Or can timezone be set while creating sqlalchemy_engine?

1 Answers

Got a solution for MySQL in How do I create mysql+pymysql engine with time_zone configured? However, same/similar approach is not working for PostgreSQL. As a workaround, I using a wrapper on read_sql and modifying the incoming query by adding set timezone statement just before the incoming query and that is working without any issue. But I am not sure if this is the best solution or not.

Related