Thanks a lot Michael.

The merge functionality is what I was looking for. This also exposed a
flaw in our model I think. We keep using the auto-increment primary
keys which would make merge() impossible to use in the scenario I was
describing. Right?


>
> The easiest way to do auto "insert or update" given an object that  
> you've loaded from a file is to use merge():
>
>         myobj = session.merge(myobj)
>
> which will do the SELECT for you.  If the object is already loaded, no  
> SELECT is emitted.
>
> So it follows then that you can SELECT all the rows of the table ahead  
> of time, keep them referenced in a collection:
>
>         all_objects = session.query(MyStuff).all()
>
> then you can merge() each element you pull from the file as needed,  
> and no additional SQL should be emitted to fetch any of it.

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