[Python] Issue with parameters of SQLAlchemy execute()

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

  1. Stack

    Stack Membro Participativo

    I have the following:

    def execute_query(sql_query, engine, params_tuple=None):
    params_tuple = params_tuple if params_tuple else {}

    with engine.connect() as connection:
    result = connection.execute(text(sql_query), params_tuple)
    connection.commit()


    This method seems to run sucessfully when params_tuple is None, but it fails otherwise. Here is an example:

    INSERT INTO x.aggregation_dates (position_date, account_id, horizon)
    VALUES (?, ?, ?)


    where params_tuple = ('2025-01-31', 12, 22)

    Why is this not working? What am I missing?

    The error I get is:


    List argument must consist only of tuples or dictionaries
    ​

    Thank you!

    Continue reading...

Compartilhe esta Página