actually, this is exactly what i didn't want to do .. at least not explicitly. thx.
On Jan 17, 3:24 am, Laurent Rahuel <laurent.rah...@gmail.com> wrote: > Hi, > > Did you first load the entry to update into the session or do you > always create new objects to be saved ? > I guess you need to: > > 1 - try to get the record from the database using the product_id or > another unique field > 2 - if the result set is not empty, > update the record using values from the XML and session.commit() > will update the database > else > create a new mapped object with values from the XML file, > session.add(ob), and session.commit() will add the record into database > > Regards, > > Laurent > > n00b a écrit : > > > greetings, > > > i'm batch processing xml documents to mysql using SA 0.5, ORM. > > > data extracted from xml docs may be new or an update in form of a > > replacement of > > the existing object (record). (one of the columns, product_id, is > > unique=True). Hence, > > SA throws, as expected, an IntegrityError (1062, duplicate Entry) when > > i'm trying to commit the revised object via session.add(obj), > > session.commit(). > > > given the xml volume at hand, i thought i could use session.merge > > rather than query every time for existence. alas, no go. get the same > > 1062 exception. obviously, i don't understand the session merge. > > > in fact, even if i query for the existence, then try and assign the > > new object to the existing object (old_obj = session.query(OBJ).filter > > (OBJ.product_id == new_obj.product.id).one(), old_obj = new_obj, > > session.add(old_obj), session.commit()), i get the dreaded 1062. > > > any insights/suggestions? > > > thx --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---