On 10/6/15 3:48 PM, Nana Okyere wrote:
> Mike,
>
> The table creation part is done. My question is about how to insert
> rows/data into a table that is dynamically created. This dynamically
> created table is not represented by a class or anything in sqlalchemy.
if the table is there you can just reflect it.
from sqlalchemy import create_engine, Table, MetaData
e = create_engine("sqlite://", echo=True)
e.execute("""
create table i_am_dynamic(x string, y string)
""")
data = [
{'x': i, 'y': i + 10} for i in range(100)
]
m = MetaData()
t = Table('i_am_dynamic', m, autoload=True, autoload_with=e)
e.execute(t.insert(), data)
# done
> I'm just wondering if you know of a nice way to do bulk / mass inserts
> into such a table without a loop of insert statements. The source of
> my data is a generator of tuples (coming from openpyxl). Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.