From: Erik Thiele <erik@thiele-hydraulik.de>
To: Passynkov, Vadim <Vadim.Passynkov@pathcom.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: get sequence value of insert command
Date: Sat, 20 Nov 2004 10:24:46 +0100
Message-ID: <20041120102446.4a887124.erik@thiele-hydraulik.de> (raw)
In-Reply-To: <C8C8E7457059D5119E4700D0B765DCB8016AA911@sinope.inside.pathcom.com>
References: <C8C8E7457059D5119E4700D0B765DCB8016AA911@sinope.inside.pathcom.com>
On Fri, 19 Nov 2004 10:57:12 -0500
"Passynkov, Vadim" <Vadim.Passynkov@pathcom.com> wrote:
> > -----Original Message-----
> > From: Erik Thiele [mailto:erik@thiele-hydraulik.de]
> > Sent: Friday, November 19, 2004 3:42 AM
> > To: pgsql-sql@postgresql.org
> > Subject: [SQL] get sequence value of insert command
> >
> > create sequence mysequence;
> >
> > create table foo(
> > id integer default nextval('mysequence'),
> > bla text,
> > wombat integer,
> > foobar date,
> > primary key(id)
> > );
> >
> > insert into foo (wombat) values (88);
> >
> > now how do i know the id of my newly inserted element? and
> > how can this be done in a completely concurrency safe way?
>
> CREATE RULE get_pkey_on_insert AS ON INSERT TO foo DO SELECT
> currval('mysequence') AS id LIMIT 1;
now that one is really great! you should definitly add it to the
faq. plus an additional explanation why the limit 1 is needed here.
thanks!
erik
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: erik@thiele-hydraulik.de, Vadim.Passynkov@pathcom.com
Subject: Re: get sequence value of insert command
In-Reply-To: <20041120102446.4a887124.erik@thiele-hydraulik.de>
* 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