'cx-Oracle missing expression when trying to copy database content with pandas and SQLAlchemy

It should be the most simple thing in the world. However, I can't make it work.

import pandas as pd
import sqlalchemy

query = """SELECT * FROM table WHERE date = DATE :date_param"""

eng = sqlalchemy.create_engine('conn-string', arraysize=1000)


pd.read_sql(query, eng, params={'date_param': '2022-01-01'})

DatabaseError: (cx_Oracle.DatabaseError) ORA-00936: missing expression

What am I missing?



Solution 1:[1]

Figured it out:

import datetime
import pandas as pd
import sqlalchemy

query = """SELECT * FROM table WHERE date = :date_param"""

eng = sqlalchemy.create_engine('conn-string', arraysize=1000)


pd.read_sql(query, eng, params={'date_param': datetime.date(2022, 2, 1)})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Filippe O. Gonçalves