[Python] Sqlalchemy and psycopg2: pandas.read_sql_query "dict is not a sequence" error with...

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    Package Versions:

    • SQLAlchemy 2.0.40
    • pandas 2.2.3
    • psycopg2-binary 2.9.10

    I am trying to run a query using pandas' native param substitution, but I can't seem to get it to run without erroring. I tried simplifying the query to:

    select *
    FROM public.bq_results br
    WHERE cast("eventDate" as date) between
    TO_DATE('%test_start_date', 'YYYYMMDD') AND TO_DATE('%test_end_date', 'YYYYMMDD')
    limit 10000


    but I get error:

    TypeError: dict is not a sequence


    when running:

    df = pd.read_sql_query(query, self.__engine, params={"test_start_date": "20250101", "test_end_date": "20250131"})


    where

    self.__engine = create_engine(f'postgresql://{self.user}:{self.password}@{self.host}:{self.port}/{self.database}')

    Continue reading...

Compartilhe esta Página