how to get id of last insert on a serial type? 
Author Message
 how to get id of last insert on a serial type?

Two quick notes/questions...

1) That would still require me to write a function for each of
   inserts to make sure that the value came back. I can't just

   was inserted, I have to know what sequence was used. The

   know anything about what was actually inserted, just that
   something was.

2) Can I lock the sequence to make sure that another INSERT
   doesn't occur before I select the currval() of the sequence?


> -----Original Message-----

> Sent: Saturday, May 18, 2002 5:52 PM
> To: Robert J. Sanford, Jr.

> Subject: Re: [GENERAL] how to get id of last insert on a
> serial type?

> > one bit that I'm currently having the largest issue with is

> > retrieve the primary key of the last row inserted into a
> > table (assuming the table is using an identity column as the
> > primary key)

> implemented as currval() on the associated sequence.  This is more
> flexible than what you describe for SQL Server, because the
> can be retrieved at any later time in the same session --- as long
> as you don't do another insert into the same table, it's
> still good.

>                    regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command

Sat, 06 Nov 2004 00:37:38 GMT
 [ 1 post ] 

 Relevant Pages 

1. Getting ID of last inserted

2. Getting the last insert Id from SQL 7

3. Problems getting last inserted ID from Oracle DB

4. Getting the Last Inserted ID of an auto increment field

5. getting last inserted id

6. Getting the last insert ID

7. getting the last inserted id

8. Getting last insert Id from SQL 7

9. Getting last insert ID from an IDENTITY column

10. The last distributor job id and the last subscriber job id do not match

11. Recordset-Getting the ID of a row inserted when the ID is IDENTITY/AUTOINCREMENT

12. problem getting the last serial value

Powered by phpBB® Forum Software