Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id E7CA22E00A8 for ; Mon, 11 Feb 2008 13:00:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 63176-04 for ; Mon, 11 Feb 2008 13:00:53 -0400 (AST) Received: from vms173001pub.verizon.net (vms173001pub.verizon.net [206.46.173.1]) by postgresql.org (Postfix) with ESMTP id 66F522E038B for ; Mon, 11 Feb 2008 13:00:48 -0400 (AST) Received: from [192.168.0.251] ([72.76.251.23]) by vms173001.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JW3002E92GHJJQA@vms173001.mailsrvcs.net> for pgsql-sql@postgresql.org; Mon, 11 Feb 2008 10:43:30 -0600 (CST) Date: Mon, 11 Feb 2008 11:55:22 -0500 From: Jean-David Beyer Subject: Re: Check before INSERT INTO In-reply-to: <024301c86cca$591c9c60$3102a8c0@dream> To: pgsql-sql@postgresql.org Message-id: <47B07DFA.8030003@verizon.net> Organization: Institute for Regimented Whimsey MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Enigmail-Version: 0.94.0.0 References: <010901c86ca6$3b66e870$3102a8c0@dream> <873arzscnu.fsf@oxford.xeocode.com> <024301c86cca$591c9c60$3102a8c0@dream> User-Agent: Thunderbird 1.5.0.9 (X11/20070317) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/82 X-Sequence-Number: 30173 Shavonne Marietta Wijesinghe wrote: > Thanks for the reply Grogory. I am trying to do a INSERT INTO. > > Here is my table. n_gen, n_sheet, tot_n_sheet are defined as Primary Key > (Serial not null) That is sure confusing. What could a DDL saying INTEGER n_gen SERIAL NOT NULL; INTEGER n_sheet SERIAL NOT NULL; INTEGER tot_n_sheet SERIAL NOT NULL; PRIMARY KEY (n_gen, n_sheet, tot_n_sheet) mean? Is this what your DDL says? Do you enter rows of this table specifying the id and expecting the three serial generators to pick non-null sequential numbers for the other three fields? I think you are very unclear about what is going on here. Are you perhaps saying the table has three (distinct) primary keys? Because if you assign them values, why would they be SERIAL? > id | n_gen | n_sheet | tot_n_sheet > ----------+-----------+-----------+------------- > a | 1 | 1 | 1 > b | 2 | 1 | 2 > x | 2 | 2 | 2 > u | 3 | 1 | 1 > r | 4 | 1 | 3 > a | 4 | 2 | 3 > s | 4 | 3 | 3 > > > So there are 2 users inserting in to the db. In my ASP page i have a > field that shows the value of n_gen +1. So when the 2 users both login > at the same time, with different sessions, they both see "7" in the > n_gen field. But when they click on the sumbit button only one record is > inserted and the other is lost. Whatever you are doing that I do not understand with your keys, if you have two users doing inserts on the same table, would you not have to run this with Serializable Isolation Level (12.2.2. in the manual)? Would this not fix your problem especially if you have a SERIAL as primary key? > > I though it was possible to change the SQL string before it does the > update.. But i can't seem to find a solution for it.. Any idea ?? > -- .~. Jean-David Beyer Registered Linux User 85642. /V\ PGP-Key: 9A2FC99A Registered Machine 241939. /( )\ Shrewsbury, New Jersey http://counter.li.org ^^-^^ 11:35:01 up 18 days, 1:21, 1 user, load average: 4.22, 4.28, 4.27