Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4E084476B4B for ; Wed, 11 Sep 2002 22:37:48 -0400 (EDT) Received: from lsh114.siteprotect.com (lsh114.siteprotect.com [66.113.130.247]) by postgresql.org (Postfix) with ESMTP id 713784769FE for ; Wed, 11 Sep 2002 22:37:47 -0400 (EDT) Received: from bethvizx (252.dsl.seattle.telisphere.com [209.191.188.252]) by lsh114.siteprotect.com (8.9.3/8.9.3) with ESMTP id VAA15780; Wed, 11 Sep 2002 21:37:42 -0500 From: "Beth Gatewood" To: "'Christopher Kings-Lynne'" , Subject: Re: writing a function to mimic mysql last_insert_id Date: Wed, 11 Sep 2002 19:37:37 -0700 Message-ID: <000f01c25a05$5c549aa0$0c00000a@bethvizx> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/88 X-Sequence-Number: 9365 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. Thanks-Beth > -----Original Message----- > From: Christopher Kings-Lynne [mailto:chriskl@familyhealth.com.au] > Sent: Wednesday, September 11, 2002 7:05 PM > To: Beth Gatewood; pgsql-sql@postgresql.org > Subject: RE: [SQL] writing a function to mimic mysql last_insert_id > > > But in Postgres, you can have as many "autoincrement" columns > in a table as > you want - how will you handle that? > > And what's wrong with select currval()? > > Chris > > > I am wondering if I can get some input on the logic that I > would need to > > code a function that would mimic mysql's last_insert_id().. > > > > Here is what last_insert_id() does in mysql: > > Returns the last automatically generated value that was > inserted into an > > AUTO_INCREMENT column. > > mysql> SELECT LAST_INSERT_ID(); > > -> 195 >