Insert a list of dictionaries using sqlalchemy effectively

I have a list containing dictionaries as elements. All dictionaries run into my schema, is there a simple or efficient way to insert this data into db using sqlalchemy?

my list is below

[{id:'12',name:'a':lang:'eng},{id:'13',name:'b':lang:'eng},{id:'14',name:'c':lang:'eng}]

and I have the circuit below

id String(10)
name String(10)
lang String(10)
+4
source share
1 answer

As stated in the SQLAchemy documentation , you can insert many records into tableyours by calling your method connection.execute(), using table.insert()your list of records as parameters, for example:

connection.execute(table.insert(), [ 
        {'id':'12','name':'a','lang':'eng'},
        {'id':'13','name':'b','lang':'eng'},
        {'id':'14','name':'c','lang':'eng'},
    ]
)

, table , , , .

+6

All Articles