Received: from tantalum.btinternet.com (tantalum.btinternet.com [194.73.73.80]) by hub.org (8.9.3/8.9.3) with ESMTP id MAA61959 for ; Mon, 6 Dec 1999 12:52:55 -0500 (EST) (envelope-from gary.stainburn@ringways.co.uk) Received: from [212.140.104.32] (helo=linux.ringways.co.uk) by tantalum.btinternet.com with esmtp (Exim 2.05 #1) id 11v2Jd-0004AM-00 for pgsql-interfaces@postgresql.org; Mon, 6 Dec 1999 17:52:50 +0000 Received: from garys.ringways.co.uk (garys.ringways.co.uk [10.1.1.2]) by linux.ringways.co.uk (8.7.6/8.7.3) with SMTP id RAA10057 for ; Mon, 6 Dec 1999 17:17:18 GMT Received: by garys.ringways.co.uk with Microsoft Mail id <01BF400D.C8C88440@garys.ringways.co.uk>; Mon, 6 Dec 1999 17:17:33 -0000 Message-ID: <01BF400D.C8C88440@garys.ringways.co.uk> From: Gary Stainburn To: "'Pgsql Interfaces'" Subject: locking on database updates Date: Mon, 6 Dec 1999 17:16:27 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id MAA61963 Hi All, I have a number of tables in my database where the key is an int4 into which I place a unique sequential number. I have learned from part experience (although not on pgsql) not to use auto-generated numbers as it makes it a nightmare to rebuild corrupted databases. I then have a parameter table with a single row in it containing the next available number for each table. There will eventually be approx 140 users on this database accessing from web browsers (apache->perl using CGI.pm and DBI/DBD::Pg) and the main table will be hit quite hard. My question is this. Is there a safe way of retrieving the next number from the parameter table in such a way that the same number cannot be retrieved twice Pseudo Code Select & lock record increment number Update record Unlock record ....... ----------------------------------------- Gary Stainburn. Work: http://www.ringways.co.uk gary.stainburn@ringways.co.uk REVCOM: http://www.revcom.dhs.org http://www.revcom.org.uk gary.stainburn@revcom.org.uk ----------------------------------------- The nice thing about standards is that there are so many of them to choose from. -- Andrew S. Tanenbaum -----------------------------------------