Re: currval question

From: Jason Earl <jason(dot)earl(at)simplot(dot)com>
To: "Andy Kriger" <akriger(at)greaterthanone(dot)com>
Cc: "Pgsql-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: currval question
Date: 2002-09-17 00:23:57
Message-ID: 87it15o44i.fsf@npa01zz001.simplot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Andy Kriger" <akriger(at)greaterthanone(dot)com> writes:

> I am trying to get the last value updated by an column
> auto-incrementing with nextval(). In MySQL, you'd use
> LAST_INSERT_ID() - in Postgre, currval() appears to do the trick.

Yes, currval is the thing to use to do this.

> Is this maintained on a per-connection basis? For example, user A
> inserts and the nextval() updates to 5, user B does 2 inserts,
> updating nextval() to 7. When user A calls currval() they should get
> 5 if the updates are per-cnx. What does psql do under the hood
> here?

currval is per connection. User A's currval would get them 5 and user
B would get 7. Basically as long as you are using the same connection
currval will do "The right thing"TM.

Jason

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ligia Pimentel 2002-09-17 01:08:50 Re: Table with 90 columns
Previous Message Nigel J. Andrews 2002-09-17 00:10:18 Re: Managing Space in PostgreSQL - DBA Perspective