Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DBF219FB2A5 for ; Wed, 7 Mar 2007 07:59:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 48405-03 for ; Wed, 7 Mar 2007 07:59:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtp-vbr13.xs4all.nl (smtp-vbr13.xs4all.nl [194.109.24.33]) by postgresql.org (Postfix) with ESMTP id 8FEF29FB2A4 for ; Wed, 7 Mar 2007 07:59:44 -0400 (AST) Received: from [192.168.1.3] (213-84-236-203.adsl.xs4all.nl [213.84.236.203]) (authenticated bits=0) by smtp-vbr13.xs4all.nl (8.13.8/8.13.8) with ESMTP id l27BxgFJ079814; Wed, 7 Mar 2007 12:59:42 +0100 (CET) (envelope-from m.p.dankoor@gmail.com) Message-ID: <45EEA8C5.9000507@gmail.com> Date: Wed, 07 Mar 2007 12:57:57 +0100 From: "M.P.Dankoor" User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Shavonne Marietta Wijesinghe CC: pgsql-sql@postgresql.org Subject: Re: PRIMARY KEY References: <003f01c760ac$c8d34980$1102a8c0@dream> In-Reply-To: <003f01c760ac$c8d34980$1102a8c0@dream> Content-Type: multipart/alternative; boundary="------------080001060303050502010905" X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.92 tagged_above=0 required=5 tests=AWL, BAYES_50, HTML_50_60, HTML_MESSAGE, SPF_NEUTRAL X-Spam-Level: X-Archive-Number: 200703/68 X-Sequence-Number: 27706 This is a multi-part message in MIME format. --------------080001060303050502010905 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, Is it possible to redesign your table as follows: create table Mod48_00_2007 ( ID text, N_GEN serial not null, FORMSTORE text, COD_NOTATIO text, PA_COGNOME text, constraint pk_Mod48_00_2007 primary key (N_GEN) ); Your insert simply becomes: INSERT INTO MOD48_00_2007 (ID, FORMSTORE, COD_NOTAIO, PA_COGNOME) VALUES ('192168217200737122012', '', '00128', 'DE MARTINIS') Do note that you do not refer to the N_GEN column, it will use the next value, please refer to http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SERIAL for more information. Mario Shavonne Marietta Wijesinghe wrote: > Hello > > I have created a table > CREATE TABLE MOD48_00_2007 ( ID text, N_GEN int PRIMARY KEY, FORMSTORE > text, COD_NOTAIO text, PA_COGNOME text); > > And i insert the rows via a form in ASP. When the form loads i have a > functin that goes and gets the value of the field N_GEN adds 1 to it > and shows it to the user. > The problem is when i have 2 users working at the same time. > > For example the last value in my field N_GEN is 2 > When both the users A and B loads the form (ASP page) it sees N_GEN = 3 :) > > So they fill in the form and user A clicks on the button OK and the > record has been inserted with N_GEN = 3. But when the user B clicks on > the button the record is not inserted because it has the same key "3" > > INSERT INTO MOD48_00_2007 (ID, N_GEN, FORMSTORE, COD_NOTAIO, > PA_COGNOME) VALUES ('192168217200737122012', '3', '', '00128', 'DE > MARTINIS') > > Is there any way i can do this automatically? i mean maybe i have to > use someother property instead of "Primary Key" ?? > > Thanks > > Shavonne Wijesinghe --------------080001060303050502010905 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello,

Is it possible to redesign your table as follows:

create table Mod48_00_2007 (
ID            text,
N_GEN         serial     not null,
FORMSTORE     text,
COD_NOTATIO   text,
PA_COGNOME    text,
constraint pk_
Mod48_00_2007 primary key (N_GEN)
);

Your insert simply becomes:
INSERT INTO MOD48_00_2007 (ID, FORMSTORE, COD_NOTAIO, PA_COGNOME) VALUES ('192168217200737122012', '', '00128', 'DE MARTINIS')

Do note that you do not refer to the N_GEN column, it will use the next value, please refer to http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SERIAL
for more information.

Mario

Shavonne Marietta Wijesinghe wrote:
Hello
 
I have created a table
CREATE TABLE MOD48_00_2007 ( ID text, N_GEN int PRIMARY KEY, FORMSTORE text, COD_NOTAIO text, PA_COGNOME text);
 
And i insert the rows via a form in ASP. When the form loads i have a functin that goes and gets the value of the field N_GEN adds 1 to it and shows it to the user.
The problem is when i have 2 users working at the same time.
 
For example the last value in my field N_GEN is 2
When both the users A and B loads the form (ASP page) it sees N_GEN = 3 :)
 
So they fill in the form and user A clicks on the button OK and the record has been inserted with N_GEN = 3. But when the user B clicks on the button the record is not inserted because it has the same key "3"
 
INSERT INTO MOD48_00_2007 (ID, N_GEN, FORMSTORE, COD_NOTAIO, PA_COGNOME) VALUES ('192168217200737122012', '3', '', '00128', 'DE MARTINIS')
 
Is there any way i can do this automatically? i mean maybe i have to use someother property instead of "Primary Key" ??
 
Thanks
 
Shavonne Wijesinghe

--------------080001060303050502010905--