Re: writing a function to mimic mysql last_insert_id

From: Joe Conway <mail(at)joeconway(dot)com>
To: Beth Gatewood <beth(at)vizxlabs(dot)com>
Cc: 'Christopher Kings-Lynne' <chriskl(at)familyhealth(dot)com(dot)au>, pgsql-sql(at)postgresql(dot)org
Subject: Re: writing a function to mimic mysql last_insert_id
Date: 2002-09-12 03:07:16
Message-ID: 3D8004E4.80004@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rudi Starcevic 2002-09-12 05:41:24 htdig & postgresql
Previous Message Beth Gatewood 2002-09-12 02:37:37 Re: writing a function to mimic mysql last_insert_id