X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D559752804 for ; Tue, 17 May 2005 04:17:47 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56516-01 for ; Tue, 17 May 2005 07:17:46 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 67DD2528F2 for ; Tue, 17 May 2005 04:17:45 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id D500A402A22; Tue, 17 May 2005 08:15:22 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id D04F715EA6; Tue, 17 May 2005 08:11:35 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15267-06; Tue, 17 May 2005 08:11:35 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 91C9415EA5; Tue, 17 May 2005 08:11:35 +0100 (BST) Message-ID: <42899927.9070801@archonet.com> Date: Tue, 17 May 2005 08:11:35 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Joel Fradkin Cc: pgsql-sql@postgresql.org Subject: Re: getting duplicate number is there a References: <000e01c55a5f$4d912d00$797ba8c0@jfradkin> In-Reply-To: <000e01c55a5f$4d912d00$797ba8c0@jfradkin> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.053 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200505/119 X-Sequence-Number: 21432 Joel Fradkin wrote: > I was using SET TRANSACTION ISOLATION LEVEL SERIALIZABLE in MSSQL. > > Is there something similar in postgres to ensure its not in the middle of > being updated? Yep - see the SQL COMMANDS reference section under SET TRANSACTION ... You could use LOCK TABLE too. See Chapter 12 - Concurrency Control for discussion. > sql = "SELECT COUNT(*) FROM tblcase WHERE LocationID = " & > intLocationID & _ > " and substr(casenum,length(casenum)-1,2) = '" & > right(year(date),2) & "' AND clientnum = '" & _ > > chrClientNum & "'" > > I will add a select just before doing the insert to see if this helps, its > not happening a bunch, but 5 6 times a day is still an issue for me. > > I use the count as a segment of my case number so each time a new case is > entered the count goes up for that location for that year. I'd be tempted to have a case_numbers table with (year,location,max_num) and lock/read/insert to that. Makes everything explicit, and means you don't have to mess around with counts/substrings. -- Richard Huxton Archonet Ltd