PostgreSQL locking problem (II)

From: "Steffen E(dot) Thorkildsen" <steffen(at)never(dot)no>
To: pgsql-sql(at)postgresql(dot)org
Subject: PostgreSQL locking problem (II)
Date: 1999-08-23 15:06:28
Message-ID: 37C16374.9BE1F605@never.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

[Hope this is the right mailing list!]

Hi,

This summer I have developed a html-based shopping system, and
I decided to use PostgreSQL for storing data. It works fine, but I
have run into an access problem. More specific: locking problem.

In my DB I have a special table, which have a column called 'ID',
and I want this to be unique, so I do something like this:

pseudo-code:

1. ID = (select max(ID) from mytable)
2. ID = ID + 1
3. insert into mytable values (ID,...)

But here comes the problem. When the PostgreSQL has a long que
of pseudo-code line 1, different processes are getting the same ID,
and the same increased ID will be inserted into mytable, and my
unique ID rule has been broken!

So how can I lock PostgreSQL before line 1, and release the lock
after line 3? Or can this pseudo sequence be done with only one
call to PostgreSQL to make unique values?

Please help me, and please send me a copy to my e-mail.

Thank you.

Steffen E. Thorkildsen

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Barron 1999-08-23 22:28:23 Re: [SQL] Expression with aggregate
Previous Message José Soares 1999-08-23 14:02:38 Re: [HACKERS] RE: [SQL] datediff function