从SQLAlchemy Core manual逐字获取的插入语句在与Oracle 11一起使用时失败:
class OrmT(Base):
__tablename__ = 'table1'
cc = Column(String(6), primary_key=True)
sector = Column(String(60))
t = OrmT.__table__
t.create(engine)
sel = select([t.c.cc, t.c.sector])
ins = t.insert().from_select(['cc', 'sector'], sel)
engine.execute(ins)
engine.commit()
错误消息如下:
DatabaseError:(DatabaseError)ORA-00933:SQL命令未正确 结束
'INSERT INTO table1 (cc, sector) SELECT table1.cc,
table1.sector \nFROM table1 RETURNING table1.cc INTO :ret_0' {'ret_0':
<cx_Oracle.STRING with value None>}
如何调整SQLAlchemy来解决它?谢谢!
更新:
ins = t.insert(inline=True).from_select(['cc', 'sector'], sel)
通过禁用主键捕获使问题消除。这不是完美的解决方案,尤其是在需要主键时。