Skip site navigation (1) Skip section navigation (2)

Re: sequence value of the record just inserted.

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Ben Kim <bkim(at)coe(dot)tamu(dot)edu>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: sequence value of the record just inserted.
Date: 2004-04-09 17:20:43
Message-ID: Pine.LNX.4.33.0404091119530.12826-100000@css120.ihs.com (view raw or flat)
Thread:
Lists: pgsql-admin
On Fri, 9 Apr 2004, Ben Kim wrote:

> 
> Dear admins,
> 
> I have a table whose primary key is a record_id with serial type. 
> 
> I would like to know, when I insert a new row, what was the value of the
> record_id that I just inserted. Since this is a multi user application, I
> cannot simply select max of the record_id or currval of the sequence.
> 
> I would appreciate an advice.

You want the functions for sequences:

nextval, currval, and setval:

http://www.postgresql.org/docs/7.4/static/functions-sequence.html

nextval and currval are transactionally safe.


In response to

pgsql-admin by date

Next:From: CHRIS HOOVERDate: 2004-04-09 17:30:00
Subject: Performance hit for turning on collectors?
Previous:From: Tom LaneDate: 2004-04-09 16:33:02
Subject: Re: Multiple disks

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group