gizli wrote:
>
> 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?


if you want to merge data over existing data then you'd have to know the
primary keys ahead of time, yes.  that doesn't mean you can't use
autoincrement keys but the typical scenario of "import data from a file
repeatedly" probably includes a deterministic primary key setup, sure.


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