【问题标题】:Using SQLALCHEMY in my Python script在我的 Python 脚本中使用 SQLALCHEMY
【发布时间】:2016-10-08 07:40:22
【问题描述】:

在我的 python 脚本中使用 SQLalchemy 引擎 API 时,我想从一个表中选择几个列,并在其他列上使用 where 子句。我的查询如下所示。我已成功连接引擎。我知道我犯了一些小错误,请帮助

connection = engine.connect()
data=connection.execute("SELECT ID FROM Table1 WHERE Column1 =='India')
connection.close()

【问题讨论】:

  • 我认为您不需要在查询中使用双等号
  • 您在发布的代码中缺少 "。

标签: python api sqlalchemy


【解决方案1】:

试试这个:

from sqlalchemy.sql import text
connection = engine.connect()
s = text("select *
    FROM Table1
    WHERE Table1.Country = 'India'")
data=connection.execute(s)

【讨论】:

    猜你喜欢
    • 2022-10-18
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多