From: Ragnar Kjørstad <postgres@ragnark.vestdata.no>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: Rainer Mager <rmager@vgkk.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: A few misc. questions.
Date: Sat, 27 May 2000 09:32:10 +0200
Message-ID: <20000527093210.B29792@vestdata.no> (raw)
In-Reply-To: <Pine.GSO.4.02A.10005261604400.12244-100000@Falk.DoCS.UU.SE>
References: <NEBBJBCAFMMNIHGDLFKGGEALCCAA.rmager@vgkk.com>
<Pine.GSO.4.02A.10005261604400.12244-100000@Falk.DoCS.UU.SE>
On Fri, May 26, 2000 at 04:15:31PM +0200, Peter Eisentraut wrote:
> On Fri, 26 May 2000, Rainer Mager wrote:
>
> > 2. Does anyone one know a standard SQL method (that works with Postgres) to
> > retrieve the primary key of a newly INSERTed record? We've found one way but
> > it will not work with order databases since it relies on reading data from
> > the sequence tables.
>
> Again, what you do with your primary keys is up to you. Ideally you won't
> need to retrieve the primary key value because you know what you just
> inserted. If you are talking about serial, then the answer is there isn't
> one because serial isn't SQL. But as someone already said, the curval
> function will do.
Another approach is something like this:
pkey=sql("select nextval('some-sequence')")
sql("insert into table values ($pkey, $data)")
--
Ragnar Kjørstad
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-admin@postgresql.org
Cc: postgres@ragnark.vestdata.no, peter_e@gmx.net, rmager@vgkk.com
Subject: Re: A few misc. questions.
In-Reply-To: <20000527093210.B29792@vestdata.no>
References: <NEBBJBCAFMMNIHGDLFKGGEALCCAA.rmager@vgkk.com> <Pine.GSO.4.02A.10005261604400.12244-100000@Falk.DoCS.UU.SE> <20000527093210.B29792@vestdata.no>
* 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