From: Richard Huxton <dev@archonet.com>
To: Albert REINER <areiner@tph.tuwien.ac.at>
Cc: pgsql-sql@postgresql.org
Subject: Re: fetching the id of a new row
Date: Sun, 11 Feb 2001 08:23:31 +0000
Message-ID: <3A864C03.A7561E33@archonet.com> (raw)
References: <Pine.NEB.4.10.10102081613240.3543-100000@what.openface.ca>
<20010209203020.A205@frithjof>
Albert REINER wrote:
>
> I do not know of a way to insert and select in one statement without
> the use of a function (what's the problem with those, by the way?),
> but as far as I can tell nextval() will return the next value for any
> backend, so if you have more than one backend inserting at the same
> time you might end up inserting with the same id twice. Instead you
Actually nextval() works fine across backends. It always increments the
sequence, so repeated calls waste numbers.
> should insert once, without specifying the id (so that the default
> value, which must be set to nextval()) will be used; to obtain the id,
> if indeed you need it, you can than select currval(), which is
> guaranteed to work on a per-backend basis.
Yep - it's either get nextval and insert or insert and check currval.
- Richard Huxton
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-sql@postgresql.org
Cc: dev@archonet.com, areiner@tph.tuwien.ac.at
Subject: Re: fetching the id of a new row
In-Reply-To: <3A864C03.A7561E33@archonet.com>
References: <Pine.NEB.4.10.10102081613240.3543-100000@what.openface.ca> <20010209203020.A205@frithjof> <3A864C03.A7561E33@archonet.com>
* 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