recommended way to insert data into a one to many relationship using python
Wolfgang Meiners
WolfgangMeiners01 at web.de
Mon May 3 02:51:13 EDT 2010
Peter Otten schrieb:
> 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
Hi Peter,
thank you for your response.
What i have got from it, is to have a (temporary) table to do the work
inside sql and not from python. I thought of a second method to do it
inside sql by an trigger
sql = """create trigger insert_new_employee instead of insert on emplist
begin
# insert floor if not exists floor
# insert (room, floor) if not exists (room, floor)
# insert (person, rid)
end"""
but i would have to learn how to write triggers. Your idea gives me a
more direct solution.
Wolfgang
More information about the Python-list
mailing list