X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B3AE4D1B45C for ; Fri, 19 Dec 2003 14:38:35 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 03405-08 for ; Fri, 19 Dec 2003 10:37:50 -0400 (AST) Received: from ms001msg.fastwebnet.it (ms001msg.fastwebnet.it [213.140.2.51]) by svr1.postgresql.org (Postfix) with ESMTP id 3CFD4D1B44B for ; Fri, 19 Dec 2003 10:37:46 -0400 (AST) Received: from ropelxp (1.40.84.105) by ms001msg.fastwebnet.it (6.7.019) id 3FCB62000020A2B6; Fri, 19 Dec 2003 15:37:40 +0100 Message-ID: <02c801c3c63d$bfebc430$0100a8c0@ropelxp> From: "Ropel" To: "Miguel Juan" , "postgre" References: <02b001c3c638$14b26650$0100a8c0@ropelxp> <005601c3c63a$821a9990$07c8a8c0@miguel2000> Subject: Re: get last oid Date: Fri, 19 Dec 2003 15:34:56 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/62 X-Sequence-Number: 3600 Yor're right, I forgot that "currval" is not influenced by other sessions... Regards Roberto ----- Original Message ----- From: "Miguel Juan" To: "Ropel" ; "postgre" Sent: Friday, December 19, 2003 3:15 PM Subject: Re: [ODBC] get last oid > Hello, > > if you make an Insert on a table with a serial, you can get the last value > of the serial inserted by your session using: > SELECT currval('Sequence_name'); > > This is better and faster than any other solution. This ensures you to get > the last sequence number asigned to your session. Doesn't matter the number > of concurrent INSERTS made by other clients. > > Regards > > Miguel Juan > > > > ----- Original Message ----- > From: Ropel > To: postgre > Sent: Friday, December 19, 2003 2:57 PM > Subject: Re: [ODBC] get last oid > > > ... You can't: some other task can do another insert between your insert and > your select, so you get the serial > of the other record, not yours ! > > ----- Original Message ----- > From: "Leeuw van der, Tim" > To: "'Ropel'" ; "postgre" > Sent: Friday, December 19, 2003 1:21 PM > Subject: RE: [ODBC] get last oid > > > > Hiya, > > > > You get the serial as a result of your select from sequence... > > > > --Tim > > > > -----Original Message----- > > From: pgsql-odbc-owner@postgresql.org > > [mailto:pgsql-odbc-owner@postgresql.org]On Behalf Of Ropel > > Sent: vrijdag 19 december 2003 13:07 > > To: postgre > > Subject: Re: [ODBC] get last oid > > > > > > Yes of course, but doing so you have the same old problem: which serial > did > > you get ?? > > > > ----- Original Message ----- > > From: "Shachar Shemesh" > > To: "Ropel" > > Cc: "postgre" > > Sent: Friday, December 19, 2003 12:38 PM > > Subject: Re: [ODBC] get last oid > > > > > > > Ropel wrote: > > > > > > >... In a well designed relational Db, every table has a (unique) > primary > > > >key: if so, you don't even need to > > > >know the oid, because the record just inserted is directly reachable > > using > > > >the PK. > > > >If your PK uses sequences, you have to get the next seq value "select > > > >nextval() from seq_xxxxx..." and use the > > > >value obtained for inserting your new row instead of using it as a > > default > > > >value; this way you are protected from > > > >concurrent writing to the DB. > > > > > > > >If you REALLY need the oid from the ODBC connection, I can't help... > > sorry ! > > > > > > > >Bye > > > > > > > >Roberto > > > > > > > > > > > > > > > Actually, if you created the sequence implicitly by using the "serial" > > > type, you don't even have to do that. You can simply do this: > > > creating the table: > > > create table foo (index serial not null, a type, b type.....); > > > inserting into the table: > > > insert into foo (a,b,....).... > > > > > > I.e. - leave the serial field out of the insert, and it will > > > automatically be set to the next sequence from the table. > > > > > > -- > > > Shachar Shemesh > > > Open Source integration & consulting > > > Home page & resume - http://www.shemesh.biz/ > > > > > > > > > > > > > > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 6: Have you searched our list archives? > > > > http://archives.postgresql.org > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html >