Re: Getting Primary Key Value After Insert

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, Adam <adam(at)spatialsystems(dot)org>, Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting Primary Key Value After Insert
Date: 2006-07-09 12:40:40
Message-ID: 20060709124040.GB4954@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Jul 08, 2006 at 11:02:26PM -0700, Richard Broersma Jr wrote:
> > > > 3. If you call currval() will it return 20? I would think it does.
> >
> > Yes it does.
> >
> > > My understanding is that it will provided your are within a transaction.
> >
> > As long as you're in the same session you're fine. You would have to go out of
> > your way to break it but if you're using some sort of connection pooling you
> > wouldn't want to pull a fresh connection from the pool, for example.
>
> Just to clarify, currval() is isolated by the session on not necessarily by a transaction?

Yes, currval() returns the value given by the last nextval() on that
sequaence in the current session.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark Morgan Lloyd 2006-07-09 12:40:56 Procedural language functions across servers
Previous Message Douglas McNaught 2006-07-09 12:34:37 Re: Getting Primary Key Value After Insert