Received: from shelob.primaerdata.no (root@shelob.primaerdata.no [195.1.90.150]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA36707 for ; Mon, 23 Aug 1999 11:07:25 -0400 (EDT) (envelope-from steffen@never.no) Received: from never.no (kunde0540.alfanett.no [195.134.35.33]) by shelob.primaerdata.no (8.9.3/8.9.3) with ESMTP id RAA09323 for ; Mon, 23 Aug 1999 17:07:10 +0200 Message-ID: <37C16374.9BE1F605@never.no> Date: Mon, 23 Aug 1999 17:06:28 +0200 From: "Steffen E. Thorkildsen" Reply-To: steffent@ifi.uio.no X-Mailer: Mozilla 4.61 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: PostgreSQL locking problem (II) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit [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