X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7CA12D1B8C9 for ; Mon, 1 Sep 2003 18:49:18 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 66748-03 for ; Mon, 1 Sep 2003 15:48:48 -0300 (ADT) Received: from tomts25-srv.bellnexxia.net (tomts25.bellnexxia.net [209.226.175.188]) by svr1.postgresql.org (Postfix) with ESMTP id 4AC99D1B8D3 for ; Mon, 1 Sep 2003 15:48:46 -0300 (ADT) Received: from acer.sympatico.ca ([65.93.70.201]) by tomts25-srv.bellnexxia.net (InterMail vM.5.01.06.04 201-253-122-130-104-20030726) with ESMTP id <20030901184845.DWTN5085.tomts25-srv.bellnexxia.net@acer.sympatico.ca> for ; Mon, 1 Sep 2003 14:48:45 -0400 Message-Id: <5.2.1.1.0.20030901144559.00a0c3e0@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Mon, 01 Sep 2003 14:48:30 -0400 To: pgsql-php@postgresql.org From: Frank Bax Subject: Re: Get last serial (autoincrement) value In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/3 X-Sequence-Number: 2280 At 06:34 AM 9/1/03, aka MacGuru wrote: >Anyone knows how to obtain last inserted serial (autoincrement) id? I am >currently using "SELECT id FROM table_name ORDER BY id DESC", and then >retrieve first row and desired value. Faster then your version: SELECT id FROM table_name ORDER BY id DESC LIMIT 1 The 'elegant' solution: SELECT currval('tablename_sequence_id');