gpt4 book ai didi

python - SQLAlchemy 类型错误 : where() got an unexpected keyword argument

转载 作者:太空宇宙 更新时间:2023-11-04 00:30:14 24 4
gpt4 key购买 nike

简单的 Python SQLAlchemy where(),但这个错误让我抓狂。想不通。

In [1]: import sqlalchemy as sa
...: import pandas as pd
...:
...: import etl_utils as eu

In [2]: engine = eu.set_db('s','username',input('enter password:\t'),
...: sql_database_name='DBNAME')

In [3]: meta = sa.MetaData(engine)
...: meta.reflect()

... 已编辑...

In [6]: tbl
Out[6]: Table('factSecurityPrices', MetaData(bind=Engine(mssql+pyodbc:///?odbc_connect=Driver={ODBC Driver 13 for SQL Server};Server=redacted)), Column('SecurityID_FK', INTEGER(), ForeignKey('dimSecurities.SecurityID_PK'), table=<factSecurityPrices>), Column('ImportInfoID_FK', INTEGER(), ForeignKey('dimImportInfo.ImportInfoID_PK'), table=<factSecurityPrices>), Column('PriceDate', DATETIME(), table=<factSecurityPrices>), Column('SecurityPrice', DECIMAL(precision=22, scale=4), table=<factSecurityPrices>), schema=None)
In [7]: tbl.update().where(ImportInfoID_FK=398).values(SecurityPrice=8.5)
Traceback (most recent call last):

File "<ipython-input-7-dfa9428585e6>", line 1, in <module>
tbl.update().where(ImportInfoID_FK=398).values(SecurityPrice=8.5)

TypeError: where() got an unexpected keyword argument 'ImportInfoID_FK'

为什么我不能将 kwarg 传递给 where()?所有示例和在线文档都表明您可以!

编辑:尝试使用评论中的建议,但没有用:

In [8]: tbl.update().where(tbl.ImportInfoID_FK=398).values(SecurityPrice=8.5)
File "<ipython-input-8-53fb97b0906a>", line 1
tbl.update().where(tbl.ImportInfoID_FK=398).values(SecurityPrice=8.5)
^
SyntaxError: keyword can't be an expression


In [9]: tbl.update().where(tbl.c.ImportInfoID_FK=398).values(SecurityPrice=8.5)
File "<ipython-input-9-c1ceb5a2591f>", line 1
tbl.update().where(tbl.c.ImportInfoID_FK=398).values(SecurityPrice=8.5)
^
SyntaxError: keyword can't be an expression

最佳答案

您需要使用 .where(tbl.c.ImportInfoID_FK==398)。参见 here以获得更多解释。

关于python - SQLAlchemy 类型错误 : where() got an unexpected keyword argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46084620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com