使用Sqlalchemy将数据插入Snowflake仓库时出现以下错误,知道吗?
错误 :
无法重写多行插入[SQL:'INSERT INTO小部件(ID,名称,类型)
选择%(id)s AS anon_1,%(name)s AS anon_2,widgets.id \ nFROM小部件\ nWHERE widgets.type =%(card_id)s']
[参数:({'id':2,'name':'Lychee','card_id':1},{'id':3,'name':'testing','card_id':2} )]
代码 :
foo :: KnownNat m => Natural -> Mod m
foo = fromIntegral
基本上,我正在尝试执行以下操作,但是Snowflake不支持此语法。
from sqlalchemy import *
from snowflake.sqlalchemy import URL
# Helper function for local debugging
def createSQLAlchemyEngine():
url = URL(
account='',
user='',
password='',
database='db',
schema='',
warehouse='',
role='',
proxy_host='',
proxy_port=8099
)
engine = create_engine(url)
return engine
conn = createSQLAlchemyEngine()
# Construct database
metadata = MetaData()
widgetTypes = Table('widgetTypes', metadata,
Column('id', INTEGER(), nullable=True),
Column('type', VARCHAR(), nullable=True))
widgets = Table('widgets', metadata,
Column('id', INTEGER(), nullable=True),
Column('name', VARCHAR(), nullable=True),
Column('type', INTEGER(), nullable=True))
engine = conn
metadata.create_all(engine)
# Connect and populate db for testing
conn = engine.connect()
sel = select([bindparam('id'), bindparam('name'), widgets.c.id]).where(widgets.c.type == bindparam('card_id'))
ins = widgets.insert().from_select(['id', 'name', 'type'], sel)
conn.execute(ins, [
# {'name': 'Melon', 'type_name': 'Squidgy'},
{'id': 2, 'name': 'Lychee', 'card_id' : 1 },
{'id': 3, 'name': 'testing', 'card_id': 2}
])
conn.close()
所以,我必须做类似的事情,但是遇到了上面的错误。
insert into tableXX
values('Z',
(select max(b) +1 from tableXX a where a.CD = 'I'), 'val1', 'val2')
目标:
代码的逻辑是我想基于与新记录具有相同“ CD”的记录的现有sequence_id的最大值来更新sequence_id。