John Siracusa wrote:
> On 6/7/07 3:04 AM, Cees Hek wrote:
>> On 6/7/07, Neal Clark <[EMAIL PROTECTED]> wrote:
>>> Also, I do not understand why Rose::DB goes to the trouble of getting 
>>> tangled
>>> up in the serial sequence when a value 'DEFAULT' for the id to the statement
>>> handler would do the same thing.
>> Usually this is done so that the code knows exactly what the primary
>> key for the row is going to be.  If you just insert using DEFAULT,
>> then you usually have to make an extra call to the DB to retrieve the
>> record again to find out what id was assigned to the row
> 
> Right, that's why RDBO pre-allocates the serial value.  I believe the Pg
> call to "get me the last value pulled from this sequence in this session" is
> also a safe way to do it, but I'm not 100% sure.  Pre-allocating is 100%
> safe in that, if the insert succeeds, I know for sure what value it used,
> with no worries about race conditions.

And not to appeal to authority, but Tom Lane suggests this same approach:

 >This is the Right Way To Do It.  You do not need the transaction
 >(because currval() is backend-private anyway).  I'd not bother with
 >currval() at all, but just do
 >
 >   SELECT nextval('some_table_id_sequence');
 >
 >   -- this returns 4242, say
 >
 >   INSERT INTO some_table(id, name, surname)
 >      VALUES(4242, 'marc', 'moua');
 >
 >Simple, reliable, fast.
 >
 >                        regards, tom lane

Maurice

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to