Re: [sqlalchemy] Re: INSERT RETURNING question
On Jan 19, 2011, at 2:54 AM, Eric Lemoine wrote: On Tue, Jan 18, 2011 at 11:33 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 18, 2011, at 4:47 PM, Eric Lemoine wrote: On Tuesday, January 18, 2011, Eric Lemoine eric.lemo...@camptocamp.com 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. I did not expect that obj.id (the primary key) would be expired, as doing SELECT id WHERE id= didn't make sense to me. well the row could have been moved/deleted so thats why PK columns are part of that check. (we of course have the identity of the object stored as well, that is separate from the primary key attributes...since they can diverge in this case). Thanks. -- Eric Lemoine Camptocamp France SAS Savoie Technolac, BP 352 73377 Le Bourget du Lac, Cedex Tel : 00 33 4 79 44 44 96 Mail : eric.lemo...@camptocamp.com 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 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. -- 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.
[sqlalchemy] Re: INSERT RETURNING question
On Tuesday, January 18, 2011, Eric Lemoine eric.lemo...@camptocamp.com 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. -- Eric Lemoine Camptocamp France SAS Savoie Technolac, BP 352 73377 Le Bourget du Lac, Cedex Tel : 00 33 4 79 44 44 96 Mail : eric.lemo...@camptocamp.com 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 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.
Re: [sqlalchemy] Re: INSERT RETURNING question
On Jan 18, 2011, at 4:47 PM, Eric Lemoine wrote: On Tuesday, January 18, 2011, Eric Lemoine eric.lemo...@camptocamp.com 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 : eric.lemo...@camptocamp.com 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 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. -- 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.
Re: [sqlalchemy] Re: INSERT RETURNING question
On 01/18/2011 10:47 PM, Eric Lemoine wrote: On Tuesday, January 18, 2011, Eric Lemoineeric.lemo...@camptocamp.com 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. Hey there, i am just guessing a little bit... maybe you need to set the following? sessionmaker(expire_on_commit=False) -- Greetings Jan Müller -- 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.
Re: [sqlalchemy] Re: INSERT RETURNING question
On Tue, Jan 18, 2011 at 11:33 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 18, 2011, at 4:47 PM, Eric Lemoine wrote: On Tuesday, January 18, 2011, Eric Lemoine eric.lemo...@camptocamp.com 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. I did not expect that obj.id (the primary key) would be expired, as doing SELECT id WHERE id= didn't make sense to me. Thanks. -- Eric Lemoine Camptocamp France SAS Savoie Technolac, BP 352 73377 Le Bourget du Lac, Cedex Tel : 00 33 4 79 44 44 96 Mail : eric.lemo...@camptocamp.com 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 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.