Re: serialization errors

From: Greg Copeland <greg(at)CopelandConsulting(dot)Net>
To: Ryan VanderBijl <rvbijl-pgsql(at)vanderbijlfamily(dot)com>
Cc: PostgresSQL General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: serialization errors
Date: 2003-01-30 19:38:40
Message-ID: 1043955519.10917.11.camel@mouse.copelandconsulting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)copelandconsulting(dot)net>
Copeland Computer Consulting

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chad Thompson 2003-01-30 19:43:09 Re: One large v. many small
Previous Message scott.marlowe 2003-01-30 19:18:23 Re: Website troubles