On Jan 18, 2011, at 4:47 PM, Eric Lemoine wrote:

> On Tuesday, January 18, 2011, Eric Lemoine <[email protected]> 
> wrote:
>> Hi
>> 
>> Probably a very simple question. I use the ORM for inserts, with
>> postgres 8.3. How can I get the ids resulting from my inserts'
>> RETURNING clauses? I haven't been able to find the information in the
>> doc.
> 
> Doing just_inserted_obj.id causes a "SELECT ... WHERE id=" query,
> which I'd like to avoid.

That sounds like you're calling commit() which is expiring all data, resulting 
in a re-fetch when you hit .id.  Just call session.flush(), then get the .id 
from your objects, before a commit() occurs.

The insert() construct used by the ORM abstracts away whether RETURNING, 
cursor.lastrowid, or some other method is used to get the server-generated 
primary key.   This is probably why searching specifically for "RETURNING/ ORM 
" is not turning anything up.



> 
> -- 
> Eric Lemoine
> 
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
> 
> Tel : 00 33 4 79 44 44 96
> Mail : [email protected]
> http://www.camptocamp.com
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to