【问题标题】:bind list to sqlalchemy query python mysql将列表绑定到 sqlalchemy 查询 python mysql
【发布时间】:2020-11-03 05:04:16
【问题描述】:

如何将列表绑定到 SQL alchemy 查询? 以下方法无效。

  1. engine.execute("DELETE FROM testing WHERE test_id IN %s", [1,2,3])
  2. engine.execute("DELETE FROM testing WHERE test_id IN %s", tuple([1,2,3]))
  3. engine.execute("DELETE FROM testing WHERE test_id IN (%s)", [1,2,3])

他们都给我错误:not all arguments converted during string formatting

【问题讨论】:

    标签: python python-3.x sqlalchemy pymysql


    【解决方案1】:

    您可以通过将列表转换为元组来将列表绑定到查询:

    engine.execute("DELETE FROM testing WHERE test_id in %(ids)s, ids=tuple([1,2,3])))
    

    【讨论】:

      猜你喜欢
      • 2019-01-18
      • 2021-12-05
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-17
      相关资源
      最近更新 更多