SQLAlchemy 插入忽略 [英] SQLAlchemy INSERT IGNORE

查看:42
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆