SQLAlchemy INSERT IGNORE

ⅰ亾dé卋堺 提交于 2019-11-27 01:53:09

问题


How can I insert multiple data records into table ignoring duplicates. I am using SQLAlchemy.

Thank you!


回答1:


prefix_with("TEXT") adds arbitrary text between INSERT and the rest of the SQL. execute() accepts a list of dictionaries with the records you would like to insert or a single dictionary if you only want to insert a single record.

The SQLite syntax for the behavior you're looking for:

inserter = table_object.insert().prefix_with("OR REPLACE")
inserter.execute([{'column1':'value1'}, {'column1':'value2'}])


来源:https://stackoverflow.com/questions/2218304/sqlalchemy-insert-ignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!