Re: serialization errors when inserting new records - Mailing list pgsql-general

From Gary Doades
Subject Re: serialization errors when inserting new records
Date
Msg-id 41F23F8B.7090809@gpdnet.co.uk
Whole thread Raw
In response to serialization errors when inserting new records  (Ralph van Etten <ralph@et10.org>)
List pgsql-general
Ralph van Etten wrote:
> Hoi,
>
> I searched the archives but couldn't find an answer to this:
>
> I have a table (simplyfied)
>
> CREATE TABLE test (
>   id   INT PRIMARY KEY,
>   name VARCHAR(250)
> );
>
> I insert records with
>
> INSERT INTO test (id, name)
> SELECT COALESCE(MAX(id)+1, 1), 'name' FROM test
>
> Ofcourse this gives problems when two clients are inserting a record at
> the same time. (duplicate primary keys) But, i can't use a sequence in my
> application (the pk consists of more than just a sequence)
>

It's not clear why you can't use a serial as the primary key or as part
of the primary key. From your example it looks like you are trying to do
exactly that.

What does your *real* primary key consist of?

Cheers,
Gary.

pgsql-general by date:

Previous
From: Tino Wildenhain
Date:
Subject: Re: serialization errors when inserting new records
Next
From: Chris Green
Date:
Subject: Re: Data entry - forms design or other APIs etc. - what is there?