From: | Erik Thiele <erik(at)thiele-hydraulik(dot)de> |
---|---|
To: | "Passynkov, Vadim" <Vadim(dot)Passynkov(at)pathcom(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: get sequence value of insert command |
Date: | 2004-11-20 09:24:46 |
Message-ID: | 20041120102446.4a887124.erik@thiele-hydraulik.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Fri, 19 Nov 2004 10:57:12 -0500
"Passynkov, Vadim" <Vadim(dot)Passynkov(at)pathcom(dot)com> wrote:
> > -----Original Message-----
> > From: Erik Thiele [mailto:erik(at)thiele-hydraulik(dot)de]
> > Sent: Friday, November 19, 2004 3:42 AM
> > To: pgsql-sql(at)postgresql(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Markus Schaber | 2004-11-20 10:44:11 | Re: Move table between schemas |
Previous Message | terry | 2004-11-20 00:16:53 | Re: NULLS and string concatenation |