> > /* 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.
True enough. You also need to do "BEGIN EXCLUSIVE;" instead of begin. Or just handle the busy condition. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com