[Zope] [SUMMARY] [SQL] Retrieving info from the previous SQL insert

Stephane Bortzmeyer bortzmeyer@netaktiv.com
Wed, 12 Dec 2001 12:26:48 +0100


On Tue, Dec 11, 2001 at 09:57:12AM +0100,
 Stephane Bortzmeyer <bortzmeyer@netaktiv.com> wrote 
 a message of 25 lines which said:

> In the first table, there is an auto-incrementing field that the
> PostgreSQL DBMS assigns itself. I need the value of that field for the
> second INSERT and I don't see how to retrieve it inside the SQL
> method.

As several people indicated here, retrieving an auto-incremented
PostgreSQL SERIAL value is done with the SQL function call currval
(TABLENAME_COLUMNNAME_seq).

I knew it (it's in PostgreSQL's FAQ) but I was unsure of the atomicity
of the complete set of SQL instructions. Apparently, I missed that in
Zope's documentation, every Zope request is atomic, even if it invokes
several SQL methods. So, it should work fine in a straightforward
way. Thanks to all.