[Python] How can I bind a list to a parameter in a custom query in SQLAlchemy?

Discussão em 'Python' iniciado por Stack, Setembro 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am using this SQL for performance reasons:

    sql_tmpl = """delete from Data where id_data in :)iddata) """
    params = {
    'iddata':[1, 2,3 4],
    }

    # 'session' is a session object from SQLAlchemy
    self.session.execute(text(sql_tmpl), params)


    However, I got an exception:

    NotSupportedError: (NotSupportedError) ('Python type list not supported. param=1', 'HY097')


    Is there a workaround that can allow me to bind a list to the parameter of the 'in' clause?

    Continue reading...

Compartilhe esta Página