recommended way to insert data into a one to many relationship using python

Peter Otten __peter__ at web.de
Sun May 2 08:13:02 EDT 2010


Peter Otten wrote:

If you create indices for floors (and rooms)

cur.execute("""create unique index room_index on rooms (fid, number);""")
cur.execute("""create unique index floor_index on floors (floor);""")

the addition of missing rows can be simplified to

missing = c2.execute("""select distinct floor from new_employees;""")
cur.executemany("insert or ignore into floors (floor) values (?)", missing)

etc.

Peter



More information about the Python-list mailing list