[Zope] Can I capture results from insert in Z SQL methods?

Dieter Maurer dieter@handshake.de
Sun, 3 Nov 2002 19:06:29 +0100


Skip Montanaro writes:
 > ...
 >     insert into contact (
 >         ...
 >         phone,
 >         ...
 >     )
 >     values (
 >         ...
 >         (select currval(phone_id_seq)),
 >         ...
 >     );
 > 
 > That will get the id of the record I just inserted assuming someone else
 > didn't sneak in and insert another row in the phone table before I queried
 > phone_id_seq.
Usually, this is not a problem, because "nextval/currval" are connection
local. Thus, a "nextval" issued in a different connection does
not affect "currval" in this connection.

Usually, you have a connection per thread. Thus, the race condition
does not occur.
There are DAs that use a single connection for several threads but
hopefully, the sequence values are then protected by the transactions.

When you ask your question on "Zope-DB@zope.org", you may get more
detailed information.


Dieter