SQLAlchemy插入信息 [英] SQLAlchemy INSERT IGNORE
本文介绍了SQLAlchemy插入信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将多个数据记录插入表中而忽略重复项.我正在使用SQLAlchemy.
How can I insert multiple data records into table ignoring duplicates. I am using SQLAlchemy.
谢谢!
推荐答案
prefix_with("TEXT")
在INSERT
和SQL的其余部分之间添加任意文本. execute()
接受包含要插入的记录的字典列表,或者如果您只想插入单个记录,则接受单个字典.
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.
您要查找的行为的SQLite语法:
The SQLite syntax for the behavior you're looking for:
inserter = table_object.insert().prefix_with("OR REPLACE")
inserter.execute([{'column1':'value1'}, {'column1':'value2'}])
这篇关于SQLAlchemy插入信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文