On Jan 17, 2009, at 4:07 AM, n00b wrote:

>
> 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?

you're on the right track, except that merge() is basing its "do i  
update an existing object" based on primary keys, not just unique  
constraints.  you'd have to merge() objects that match up to those you  
want to update based on primary key.   if your tables don't look like  
that, you can still configure the mapper() to consider any arbitrary  
set of columns as primary key columns using the "primary_key" argument.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to