>  From:        Dan Kennedy [mailto:[EMAIL PROTECTED]
>  Sent:        Wed 10/5/2005 11:30 PM

>  /* Retrieve next id in sequence: */
>  BEGIN;
>  SELECT id FROM id_allocator;          /* This is the id to use */
>  UPDATE id_allocator SET id = id + 1;
>  COMMIT;   /* Can't use the id until the transaction successfully commits! */

Just a side note; Traditionally this is done the other way around, i.e. update 
then select. The reason for this is the (small) window in the critical section 
for another session to issue the select at the same time causing a deadlock. 
Locking the table exclusively at the beginnng of the transaction avoids that 
problem.

Chris

Reply via email to