pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steffen E. Thorkildsen <steffen@never.no>
To: pgsql-sql@postgresql.org
Subject: PostgreSQL locking problem (II)
Date: Mon, 23 Aug 1999 17:06:28 +0200
Message-ID: <37C16374.9BE1F605@never.no> (raw)

[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



Message-ID: <37C16374.9BE1F605@never.no>
Permalink:  ../37C16374.9BE1F605@never.no/
Also on:    postgresql.org/message-id/37C16374.9BE1F605@never.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: steffen@never.no
  Subject: Re: PostgreSQL locking problem (II)
  In-Reply-To: <37C16374.9BE1F605@never.no>
  References: <37C16374.9BE1F605@never.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox