Re: serialization errors - Mailing list pgsql-general

From Greg Copeland
Subject Re: serialization errors
Date
Msg-id 1043955519.10917.11.camel@mouse.copelandconsulting.net
Whole thread Raw
In response to Re: serialization errors  (Ryan VanderBijl <rvbijl-pgsql@vanderbijlfamily.com>)
Responses Re: serialization errors
List pgsql-general
On Thu, 2003-01-30 at 13:00, Ryan VanderBijl wrote:
> I guess I'm starting to sound like a broken record here, but I'm struggling
> to understand why it should say unique constraint violated instead of serial.
>

Because, the "select max(node_order)+1" will select the identical value
in multiple sessions.  Done concurrently, it results in unique
constraint violation on your insert, even if the inserts are serialized.

--------------------
session 1; parallel:
    select max(node_order)+1 = 5

session 2; parallel:
    select max(node_order)+1 = 5

--------------------
session 1, session 2; serialized:
    insert into x ( order ) values ( 5 )
    insert into x ( order ) values ( 5 )

As you can see from the fast and crude example, serializing the inserts
are not going to protect you from attempting to insert the same value
into your table twice.

That help clarify it?  Then again, perhaps I misunderstood what you're
trying to do.... ;)


Regards,


--
Greg Copeland <greg@copelandconsulting.net>
Copeland Computer Consulting


pgsql-general by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: Website troubles
Next
From: "scott.marlowe"
Date:
Subject: Re: Website troubles