On Oct 21, 2009, at 7:03 PM, Josh Stratton wrote:
> >> 2. load-each-row-at-a-time >> >> just remove the first query. the session will then look up things >> using >> merge() as you ask. > > But wouldn't this still cause an insertion error when I try merging a > job object, who's userName is already in the table? you'd need to establish the "primary key" from the mapper's point of view in terms of both userId and userName. mapper() accepts a "primary_key" argument for this purpose. Alternatively you can just issue a query() for each object as you insert, or like the "load everything first" load them all into a dict, i.e. dict(((e.userId, e.userName), e) for e in sess.query(MyObject).all ()). Basically mimic the same functionality adding userName as part of the key. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---