Skip site navigation (1) Skip section navigation (2)

Re: get last oid

From: "Ropel" <ropel(at)ropel(dot)it>
To: "postgre" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: get last oid
Date: 2003-12-19 13:57:42
Message-ID: 02b001c3c638$14b26650$0100a8c0@ropelxp (view raw or flat)
Thread:
Lists: pgsql-odbc
... 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" <tim(dot)leeuwvander(at)nl(dot)unisys(dot)com>
To: "'Ropel'" <ropel(at)ropel(dot)it>; "postgre" <pgsql-odbc(at)postgresql(dot)org>
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(at)postgresql(dot)org
> [mailto:pgsql-odbc-owner(at)postgresql(dot)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" <psql(at)shemesh(dot)biz>
> To: "Ropel" <ropel(at)ropel(dot)it>
> Cc: "postgre" <pgsql-odbc(at)postgresql(dot)org>
> 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
>



In response to

Responses

pgsql-odbc by date

Next:From: Leeuw van der, TimDate: 2003-12-19 14:13:34
Subject: Re: get last oid
Previous:From: Leeuw van der, TimDate: 2003-12-19 12:21:40
Subject: Re: get last oid

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group