Re: currval question - Mailing list pgsql-general

From Jason Earl
Subject Re: currval question
Date
Msg-id 87it15o44i.fsf@npa01zz001.simplot.com
Whole thread Raw
In response to currval question  ("Andy Kriger" <akriger@greaterthanone.com>)
List pgsql-general
"Andy Kriger" <akriger@greaterthanone.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

pgsql-general by date:

Previous
From: "Nigel J. Andrews"
Date:
Subject: Re: Managing Space in PostgreSQL - DBA Perspective
Next
From: "Ligia Pimentel"
Date:
Subject: Re: Table with 90 columns