camlost wrote: > Thank you for the reply. > > However, this solution (though I'm ready to use it) would create a lot > of SQL queries comparing it with simple INSERT ... ON DUPLICATE KEY > UPDATE. > On the other hand, I admit the INSERT ... IN DUPLICATE KEY UPDATE > might not be available in other DBs. I would like the application > would be independent of the database engine bellow. > > So... is there some way how to achieve this while keeping number of > SQL queries low? :-) > (The number of objects handled this way is about 20 000.)
Sure, if your process will be the only one inserting and changing these rows. Working through your 20k python objects in batches of 1000 or whatever size you like, collect the key values from the python objects. Run a database select to see which of those keys are present in the database, and then divide your batch into two parts: data needing insert and data needing update. If you've got write contention for this data you'd need to work more granularly (likely row by row) instead, keeping in mind the database engine's transaction model and ideally taking advantage of any tools the db engine provides (like ON DUPLICATE or sql's MERGE) . Performance and engine agnosticism may be mutually exclusive here. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---