From shavonne.marietta@studioform.it Wed Mar 7 11:36:06 2007 Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 6D6D59FB648 for ; Wed, 7 Mar 2007 07:36:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 93538-05 for ; Wed, 7 Mar 2007 07:35:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtpout21.attiva.biz (smtpout21.attiva.biz [85.37.16.23]) by postgresql.org (Postfix) with ESMTP id 92C2A9FB61C for ; Wed, 7 Mar 2007 07:35:57 -0400 (AST) Received: from FBCMFE02B15.fbc.local ([192.168.30.161]) by smtpout21.attiva.biz with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Mar 2007 12:35:54 +0100 Received: from dream ([88.34.161.130]) by FBCMFE02B15.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Mar 2007 12:35:52 +0100 Message-ID: <003f01c760ac$c8d34980$1102a8c0@dream> Reply-To: "Shavonne Marietta Wijesinghe" From: "Shavonne Marietta Wijesinghe" To: Subject: PRIMARY KEY Date: Wed, 7 Mar 2007 12:35:58 +0100 Organization: Studio FORM MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_003C_01C760B5.28165DD0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-OriginalArrivalTime: 07 Mar 2007 11:35:52.0935 (UTC) FILETIME=[C33A0770:01C760AC] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.709 tagged_above=0 required=5 tests=AWL, BAYES_50, HTML_50_60, HTML_MESSAGE, SUBJ_ALL_CAPS X-Spam-Level: X-Archive-Number: 200703/66 X-Sequence-Number: 27704 This is a multi-part message in MIME format. ------=_NextPart_000_003C_01C760B5.28165DD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 =3D = 3 :) So they fill in the form and user A clicks on the button OK and the = record has been inserted with N_GEN =3D 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 ------=_NextPart_000_003C_01C760B5.28165DD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello
 
I have created a table
CREATE TABLE MOD48_00_2007 ( ID text, = N_GEN int=20 PRIMARY KEY, FORMSTORE text, COD_NOTAIO text, PA_COGNOME = text);
 
And i insert the rows = via a form=20 in ASP. When the form loads i have a functin that goes and gets the = value=20 of the field N_GEN adds 1 to it and shows it to the=20 user.
The problem is when i = have 2 users=20 working at the same time.
 
For example the last value in my field N_GEN is=20 2
When both the users A and B loads the form (ASP = page) it=20 sees N_GEN =3D 3 :)
 
So they fill in the form and user A clicks on = the button=20 OK and the record has been inserted with N_GEN =3D 3. But when the user = B clicks=20 on the button the record is not inserted because it has the same key=20 "3"
 
INSERT INTO MOD48_00_2007 (ID, N_GEN, = FORMSTORE,=20 COD_NOTAIO, PA_COGNOME) VALUES ('192168217200737122012', '3', '', = '00128', 'DE=20 MARTINIS')
 
Is there any way i can do this automatically? i = mean maybe=20 i have to use someother property instead of "Primary Key" = ??
 
Thanks
 
Shavonne = Wijesinghe
------=_NextPart_000_003C_01C760B5.28165DD0-- From dev@archonet.com Wed Mar 7 11:53:01 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 425869FB548 for ; Wed, 7 Mar 2007 07:53:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 54784-05 for ; Wed, 7 Mar 2007 07:52:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id CF90B9FB463 for ; Wed, 7 Mar 2007 07:52:57 -0400 (AST) Received: from server3.office.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 0DDBA77112; Wed, 7 Mar 2007 11:51:08 +0000 (GMT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id AAA57274067; Wed, 7 Mar 2007 11:51:07 +0000 (GMT) Message-ID: <45EEA72B.1020607@archonet.com> Date: Wed, 07 Mar 2007 11:51:07 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) 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: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.209 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200703/67 X-Sequence-Number: 27705 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. Check the manuals for "sequences" and "serial type". -- Richard Huxton Archonet Ltd From m.p.dankoor@gmail.com Wed Mar 7 11:59:53 2007 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-- From m.p.dankoor@gmail.com Wed Mar 7 12:52:48 2007 Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 38DD19FB31D for ; Wed, 7 Mar 2007 08:52:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 82063-01 for ; Wed, 7 Mar 2007 08:52:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtp-vbr9.xs4all.nl (smtp-vbr9.xs4all.nl [194.109.24.29]) by postgresql.org (Postfix) with ESMTP id B57FC9FB272 for ; Wed, 7 Mar 2007 08:52:42 -0400 (AST) Received: from [192.168.1.3] (213-84-236-203.adsl.xs4all.nl [213.84.236.203]) (authenticated bits=0) by smtp-vbr9.xs4all.nl (8.13.8/8.13.8) with ESMTP id l27Cqedv069126 for ; Wed, 7 Mar 2007 13:52:41 +0100 (CET) (envelope-from m.p.dankoor@gmail.com) Message-ID: <45EEB52F.4080604@gmail.com> Date: Wed, 07 Mar 2007 13:50:55 +0100 From: "M.P.Dankoor" User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: PRIMARY KEY References: <003f01c760ac$c8d34980$1102a8c0@dream> <45EEA8C5.9000507@gmail.com> <1173269986.4925.64.camel@phillip-desktop> In-Reply-To: <1173269986.4925.64.camel@phillip-desktop> Content-Type: multipart/alternative; boundary="------------060307090602040208030400" X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.097 tagged_above=0 required=5 tests=AWL, BAYES_50, HTML_30_40, HTML_MESSAGE, SPF_NEUTRAL X-Spam-Level: * X-Archive-Number: 200703/69 X-Sequence-Number: 27707 This is a multi-part message in MIME format. --------------060307090602040208030400 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Phillip Smith wrote: > If you actually need to know the value of N_GEN in your ASP > application, you will need to query the database first and select the > NEXTVAL from the sequence that the "serial" data type will create, > then use that returned value in your insert - ie, DON'T exclude it > from the insert, otherwise it will default to NEXTVAL again and return > a different value. > > The only catch with this is that you most likely won't end up with > contiguous values in this column - ie, if a user cancels after you > seect nextval, but before you insert - the value of the sequence has > already increased, and will be increased again before returning a > value when you next select nextval > That's precisely why I would not use the nextval call, you might end up with gaps. Moreover you are making 2 database calls instead of one. But then again, if your application needs to know the value you can't really avoid using nextval (good thing it's concurrency proof) Mario Phillip Smith wrote: > If you actually need to know the value of N_GEN in your ASP > application, you will need to query the database first and select the > NEXTVAL from the sequence that the "serial" data type will create, > then use that returned value in your insert - ie, DON'T exclude it > from the insert, otherwise it will default to NEXTVAL again and return > a different value. > > The only catch with this is that you most likely won't end up with > contiguous values in this column - ie, if a user cancels after you > seect nextval, but before you insert - the value of the sequence has > already increased, and will be increased again before returning a > value when you next select nextval > > Cheers, > ~p > > On Wed, 2007-03-07 at 12:57 +0100, M.P.Dankoor wrote: >> 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 >>> >> > > ********************Confidentiality and Privilege > Notice******************** > > The material contained in this message is privileged and confidential > to the addressee. If you are not the addressee indicated in this > message or responsible for delivery of the message to such person, you > may not copy or deliver this message to anyone, and you should destroy > it and kindly notify the sender by reply email. > > Information in this message that does not relate to the official > business of Weatherbeeta must be treated as neither given nor endorsed > by Weatherbeeta. Weatherbeeta, its employees, contractors or > associates shall not be liable for direct, indirect or consequential > loss arising from transmission of this message or any attachments > --------------060307090602040208030400 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Phillip Smith wrote:
If you actually need to know the value of N_GEN in your ASP application, you will need to query the database first and select the NEXTVAL from the sequence that the "serial" data type will create, then use that returned value in your insert - ie, DON'T exclude it from the insert, otherwise it will default to NEXTVAL again and return a different value.

The only catch with this is that you most likely won't end up with contiguous values in this column - ie, if a user cancels after you seect nextval, but before you insert - the value of the sequence has already increased, and will be increased again before returning a value when you next select nextval


That's precisely why I would not use the nextval call, you might end up with gaps. Moreover you are making 2 database calls instead of one.
But then again, if your application needs to know the value you can't really avoid using nextval (good thing it's concurrency proof)

Mario


Phillip Smith wrote:
If you actually need to know the value of N_GEN in your ASP application, you will need to query the database first and select the NEXTVAL from the sequence that the "serial" data type will create, then use that returned value in your insert - ie, DON'T exclude it from the insert, otherwise it will default to NEXTVAL again and return a different value.

The only catch with this is that you most likely won't end up with contiguous values in this column - ie, if a user cancels after you seect nextval, but before you insert - the value of the sequence has already increased, and will be increased again before returning a value when you next select nextval

Cheers,
~p

On Wed, 2007-03-07 at 12:57 +0100, M.P.Dankoor wrote:
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



*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to the addressee. If you are not the addressee indicated in this message or responsible for delivery of the message to such person, you may not copy or deliver this message to anyone, and you should destroy it and kindly notify the sender by reply email.

Information in this message that does not relate to the official business of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta. Weatherbeeta, its employees, contractors or associates shall not be liable for direct, indirect or consequential loss arising from transmission of this message or any attachments


--------------060307090602040208030400-- From shavonne.marietta@studioform.it Wed Mar 7 13:16:16 2007 Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 56FD19FB648 for ; Wed, 7 Mar 2007 09:16:16 -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 67396-08 for ; Wed, 7 Mar 2007 09:16:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtpout18.attiva.biz (smtpout18.attiva.biz [85.37.16.20]) by postgresql.org (Postfix) with ESMTP id 0F0849FB252 for ; Wed, 7 Mar 2007 09:16:10 -0400 (AST) Received: from fbcmfe02b11.fbc.local ([192.168.30.92]) by smtpout18.attiva.biz with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Mar 2007 14:16:06 +0100 Received: from dream ([88.34.161.130]) by fbcmfe02b11.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Mar 2007 14:16:06 +0100 Message-ID: <007301c760ba$c8acf470$1102a8c0@dream> Reply-To: "Shavonne Marietta Wijesinghe" From: "Shavonne Marietta Wijesinghe" To: References: <003f01c760ac$c8d34980$1102a8c0@dream> <45EEA8C5.9000507@gmail.com> Subject: Re: PRIMARY KEY Date: Wed, 7 Mar 2007 14:16:14 +0100 Organization: Studio FORM MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0070_01C760C3.2A086170" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-OriginalArrivalTime: 07 Mar 2007 13:16:06.0430 (UTC) FILETIME=[C38C8BE0:01C760BA] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.253 tagged_above=0 required=5 tests=AWL, BAYES_50, HTML_50_60, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200703/70 X-Sequence-Number: 27708 This is a multi-part message in MIME format. ------=_NextPart_000_0070_01C760C3.2A086170 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks alot Mario. It did exactly what i wanted. I shall also take alook = at the link you gave for more details.. Shavonne Wijesinghe ----- Original Message -----=20 From: M.P.Dankoor=20 To: Shavonne Marietta Wijesinghe=20 Cc: pgsql-sql@postgresql.org=20 Sent: Wednesday, March 07, 2007 12:57 PM Subject: Re: [SQL] PRIMARY KEY 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-SER= IAL for more information. Mario Shavonne Marietta Wijesinghe wrote:=20 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 = =3D 3 :) So they fill in the form and user A clicks on the button OK and the = record has been inserted with N_GEN =3D 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 ------=_NextPart_000_0070_01C760C3.2A086170 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thanks alot Mario. It did exactly what = i wanted. I=20 shall also take alook at the link you gave for more = details..
 
 
Shavonne Wijesinghe
 
----- Original Message -----
From:=20 M.P.Dankoor
To: Shavonne Marietta = Wijesinghe=20
Sent: Wednesday, March 07, 2007 = 12:57=20 PM
Subject: Re: [SQL] PRIMARY = KEY

Hello,

Is it possible to redesign your table as=20 follows:

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

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

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

Mario

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

------=_NextPart_000_0070_01C760C3.2A086170--