[Wellington-pm] Perl database stuff....
Sam Vilain
sam at vilain.net
Wed Dec 27 03:19:01 PST 2006
michael at diaspora.gen.nz wrote:
> A: select 1 from table where business_key = ...; # off to database
> if select returned nothing
> begin
> B: select sequence.nextval into id; # off to database
> C: insert into table values (id, business_key); # off to database
> end;
>
> Between A and B, unless you wrap a lock around the operation, there's a
> race condition; you could find either C failing (if there's a uniqueness
> constraint on "business_key"), or duplicate values in "table" (if
> there isn't).
Surely just wrapping the entire operation in a transaction is enough?
Or is that one of those cases that needs the TRANSACTION ISOLATION LEVEL
set to max?
Sam.
More information about the Wellington-pm
mailing list