Re: writing a function to mimic mysql last_insert_id - Mailing list pgsql-sql

From Joe Conway
Subject Re: writing a function to mimic mysql last_insert_id
Date
Msg-id 3D8004E4.80004@joeconway.com
Whole thread Raw
In response to Re: writing a function to mimic mysql last_insert_id  ("Beth Gatewood" <beth@vizxlabs.com>)
List pgsql-sql
Beth Gatewood wrote:
> well, I know that I will have only a single sequence that will generate the
> primary key per table.  So basically, this type of function, for me needs
> only to return the value of the primary key.
> 
> I believe I mentioned in one of my posts the motivation behind not wanting
> to use currval()...which was to trying to avoid having the developers make a
> lot of sql revisions to their application.

Maybe you could use the *same* sequence for the primary key of all the tables, 
say "my_global_seq" (it is bigint as of 7.2 I think), and then wrap a 
last_insert_id() (or whatever it is called) function around a call to 
currval('my_global_seq').

HTH,

Joe






pgsql-sql by date:

Previous
From: "Beth Gatewood"
Date:
Subject: Re: writing a function to mimic mysql last_insert_id
Next
From: Rudi Starcevic
Date:
Subject: htdig & postgresql