Ishan Bhatt Ishan Bhatt - 1 year ago 131
Python Question

Insert a list of dictionary using sqlalchemy efficiently

I have a list containing dictionaries as elements. All the dictionaries confronts to my schema, is there a simple or efficient way to insert these details in db with sqlalchemy?

my list is below


and I am having a schema given below

id String(10)
name String(10)
lang String(10)

Answer Source

As stated in SQLAchemy documentation, you can insert many records in your table by calling your connection.execute() method, using table.insert() and your list of records as it's parameters, like this:

connection.execute(table.insert(), [ 

Assuming, of course, that your table really has those column names as stated in your dictionary's keys and your values doesn't violate any constraint that you might have defined.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download