I often mix up the SQL expression language with the use of an ORM session, 
and it is great that SQLAlchemy more than supports this.

But... what are the recommended ways to keep the session in sync with what 
you do with the SQL expression stuff?

For example, with the ORM you can't really do a batch/bulk insert (that I 
know of), but you *can* mix in some SQL expression language to achieve it. 
 Here is a complete example that shows this for the standard Users/Addresses 
example:
http://pastebin.com/BArU6hci

In there I do a semi-bulk insert of addresses using both the "ORM way" and 
the "SQL Expression Language way".  With the former way, the inserted 
addresses are available *with their ids* without ever seeming to have a 
query emitted to get them.  With the latter way (SQLEL) the ORM needed to 
emit a query to get the addresses (even when I don't ask for id), presumably 
to update it's identity map.

Although the latter behaviour isn't really surprising, can the query be 
avoided somehow?  Is there a way to manually update the session/identity-map 
with the info?

In general, is there a better way to do what I'm doing?  The example is 
obviously a simplified one... my actual use case is batch inserting 
thousands of records this way and I'd like to be able to keep the ORM and 
avoid the extra query if I could.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/rnzqnwQl858J.
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