Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 91A1A2E008B for ; Fri, 11 Apr 2008 14:58:37 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 32037-05 for ; Fri, 11 Apr 2008 14:58:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from main2.mycybernet.net (main2.mycybernet.net [209.222.63.140]) by developer.postgresql.org (Postfix) with ESMTP id 757642E005D for ; Fri, 11 Apr 2008 14:58:27 -0300 (ADT) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227] helo=crankycanuck.ca) by main2.mycybernet.net with esmtp (Exim 4.62) (envelope-from ) id 1JkNVm-0004BI-60 for pgsql-sql@postgresql.org; Fri, 11 Apr 2008 13:58:06 -0400 Received: by crankycanuck.ca (Postfix, from userid 1000) id EEA855014A; Fri, 11 Apr 2008 13:57:44 -0400 (EDT) Date: Fri, 11 Apr 2008 13:57:44 -0400 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: Get the last inserted id Message-ID: <20080411175744.GA29043@crankycanuck.ca> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/80 X-Sequence-Number: 30619 On Fri, Apr 11, 2008 at 07:23:04PM +0200, Nacef LABIDI wrote: > Hi all, > > I was wondering if postgres can return the last ID inserted for a table > which the primary key is autoincremented. I need to retrieve this ID in my > code to continue processing on that inserted row. Use select currval() on the sequence name. A