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

From Ralph van Etten
Subject serialization errors when inserting new records
Date
Msg-id Pine.LNX.4.44.0501221059550.2241-100000@exp-toy.et10.loc
Whole thread Raw
Responses Re: serialization errors when inserting new records  (Tino Wildenhain <tino@wildenhain.de>)
Re: serialization errors when inserting new records  (Gary Doades <gpd@gpdnet.co.uk>)
List pgsql-general
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)

one solution would be to do a  'LOCK TABLE test IN SHARE MODE' before
inserting. This solves my problem but i'm not sure if its the
best way to deal with this kind of concurrency problems ? Is there a
better way ?



Thanks in advance.

Ralph.






pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: plpythonu on 7.4
Next
From: Tino Wildenhain
Date:
Subject: Re: serialization errors when inserting new records