【发布时间】:2021-05-19 07:08:44
【问题描述】:
我正在尝试将其插入到 postgres 表中,其中某些列具有“。”以他们的名义。 列名示例:country.name。 最好不要更改列名。
当我尝试这样做时,我得到一个错误。
def upsert(df: DataFrame, engine: sql_engine) -> None:
with engine.connect() as conn:
base = automap_base()
base.prepare(engine, reflect=True, schema="some_schema")
table1= Table('table1', base.metadata,
autoload=True, autoload_with=engine, schema="some_schema")
stmt = insert(table1).values(df.to_dict('records'))
conn.execute(stmt.on_conflict_do_update(
constraint='table1_pkey',
set_=dict(country.name=stmt.excluded.country.name
)))
我收到以下错误:
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
我一直在尝试遵循这个在列名出现“。”之前运行良好的食谱。 https://docs.sqlalchemy.org/en/14/dialects/postgresql.html#updating-using-the-excluded-insert-values
有什么建议吗?
【问题讨论】:
标签: python postgresql sqlalchemy upsert