Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 410902E026C for ; Tue, 12 Feb 2008 08:01:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 51750-08 for ; Tue, 12 Feb 2008 08:00:54 -0400 (AST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by postgresql.org (Postfix) with ESMTP id 2AB812E026A for ; Tue, 12 Feb 2008 08:01:09 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by ptb-relay03.plus.net with esmtp (Exim) id 1JOtov-0000pi-IN; Tue, 12 Feb 2008 12:01:05 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id DD684274059; Tue, 12 Feb 2008 12:01:03 +0000 (GMT) Message-ID: <47B18A80.4030802@archonet.com> Date: Tue, 12 Feb 2008 12:01:04 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Shavonne Marietta Wijesinghe CC: Jean-David Beyer , pgsql-sql@postgresql.org Subject: Re: Check before INSERT INTO References: <010901c86ca6$3b66e870$3102a8c0@dream> <873arzscnu.fsf@oxford.xeocode.com> <024301c86cca$591c9c60$3102a8c0@dream> <47B07DFA.8030003@verizon.net> <00ae01c86d5e$0f2b2ba0$3102a8c0@dream> <47B1767F.3030802@archonet.com> <00fa01c86d67$47e04bc0$3102a8c0@dream> In-Reply-To: <00fa01c86d67$47e04bc0$3102a8c0@dream> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 667dc96511c9e06ae11a4c17d1a3c551 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/94 X-Sequence-Number: 30185 Shavonne Marietta Wijesinghe wrote: > Even though n_gen is defined as a serial I can't let it handle the > progressive key by its self since there is the need that some records > should have the same value. Of course you can - the default is only provided if you don't provide your own. > That's why i use 3 primary keys. No, you're not. By definition you can only have one primary key. You are using a 3-column primary key. > A | B | C > ---+---+--- > 1 | 1 | 1 > 2 | 1 | 3 > 2 | 2 | 3 > 2 | 3 | 3 > 3 | 1 | 2 > 3 | 2 | 2 > 4 | 1 | 1 > > The 3 keys A, B, C are defined as Serial and Primay Keys You don't have 3 keys, you have 3 columns and one primary key (A,B,C). I'm not clear why B and C are serial - I don't see what that gets you. > Anyway the other suggestion, Blocking the second user from reading the > db. So for the second user I could give A temp key something like 0 and > then do a select before the submit and change the value. > > But how is it possible to know if some other user is reading the db?? Don't try. If you want to insert some rows with a new value for A do something like: INSERT INTO my_shevi (a,b,c) VALUES (DEFAULT, 1, 1); or INSERT INTO my_shevi (a,b,c) VALUES (nextval(, 1, 1); INSERT INTO my_shevi (a,b,c) VALUES (currval(), 1, 2); INSERT INTO my_shevi (a,b,c) VALUES (currval(), 1, 3); etc. Relevant parts of the manual (in 8.3 anyway): 9.15. Sequence Manipulation Functions 9.22. System Information Functions The second chapter is for pg_get_serial_sequence() which might be useful if you need to do this a lot. Oh - and please try trimming unwanted parts of the message when you reply. There was 100 unnecessary lines below here. -- Richard Huxton Archonet Ltd