I have data in a 2D tuple (or say coming from a Numpy table), and need to insert it into an SQL table. Using Sqlalchemy Core with SQLite, how can I efficiently and simply insert this data into my table?
Take i.e. from @eclaird;
engine = sa.create_engine('sqlite://', echo=True)
metadata = sa.MetaData()
widgets_table = sa.Table('widgets', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('bar', sa.String(50)),
sa.Column('biz', sa.Boolean),
sa.Column('baz', sa.Integer),
)
metadata.create_all(engine)
# Assuming this is the data where None holds place for primary key
my_data = [
(None, "Test", True, 3),
(None, "Test", True, 3),
]
So far I'm at this point in the docs; so I have;
engine.execute(widgets_table.insert().values((None, "Test", True, 3)))
Which works. But I want to insert many rows at once such as
engine.execute(widgets_table.insert().values(((None, "Test", True, 3), (None, "Test", True, 3))))
But then error;
The 'sqlite' dialect with current database version settings does not support in-place multirow inserts.
Also tried;
insert = widgets_table.insert()
engine.execute(insert, [
(None, "Test", True, 3),
(None, "Test", True, 3)
])
With error;
AttributeError: 'tuple' object has no attribute 'keys'
As a recent convert to SQLalch, I'm a bit lost here.