SQLAlchemy INSERT IGNORE

2019-01-22 18:56发布

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

Thank you!

1条回答
相关推荐>>
2楼-- · 2019-01-22 19:30

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'}])
查看更多
登录 后发表回答