pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shachar Shemesh <psql@shemesh.biz>
To: Ropel <ropel@ropel.it>
Cc: postgre <pgsql-odbc@postgresql.org>
Subject: Re: get last oid
Date: Fri, 19 Dec 2003 13:38:23 +0200
Message-ID: <3FE2E32F.5080303@shemesh.biz> (raw)
In-Reply-To: <024501c3c60e$ebc9ab50$0100a8c0@ropelxp>
References: <034201c3c5c3$de1e05f0$0200a8c0@bandeng>
	<002001c3c600$eb3f9c20$0100a8c0@ropelxp>
	<044a01c3c609$b4772ba0$0200a8c0@bandeng>
	<024501c3c60e$ebc9ab50$0100a8c0@ropelxp>

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/





view thread (14+ messages)  latest in thread

Message-ID: <3FE2E32F.5080303@shemesh.biz>
Permalink:  ../3FE2E32F.5080303@shemesh.biz/
Also on:    postgresql.org/message-id/3FE2E32F.5080303@shemesh.biz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: psql@shemesh.biz, ropel@ropel.it
  Subject: Re: get last oid
  In-Reply-To: <3FE2E32F.5080303@shemesh.biz>
  References: <034201c3c5c3$de1e05f0$0200a8c0@bandeng> <002001c3c600$eb3f9c20$0100a8c0@ropelxp> <044a01c3c609$b4772ba0$0200a8c0@bandeng> <024501c3c60e$ebc9ab50$0100a8c0@ropelxp> <3FE2E32F.5080303@shemesh.biz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox