【发布时间】:2020-07-10 00:24:54
【问题描述】:
我在 PostgreSQL 数据库中有两个表;表 1,表 2。它们都包含一个 id 列。我想将 table2 中的一列(比如 col1)添加到 table1 中,其中 table1.id = table2.id。
我试图通过 SQLalchemy 来实现这一点。我不断收到以下错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "INNER"
这是一个sn-p的代码:
engine = create_engine(...)
with engine.connect() as con:
con.execute("ALTER TABLE table1 ADD COLUMN col1 text")
con.execute("UPDATE table1 \
INNER JOIN table2 ON table1.id = table2.id \
SET table1.col1 = table2.col1")
为什么会出现这个错误?
【问题讨论】:
标签: sql python-3.x postgresql