X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 86DC1528C7 for ; Thu, 7 Jul 2005 15:03:40 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79883-09 for ; Thu, 7 Jul 2005 18:03:31 +0000 (GMT) Received: from mr2.surnet.cl (smtp2.surnet.cl [216.155.73.163]) by svr1.postgresql.org (Postfix) with ESMTP id 1237152835 for ; Thu, 7 Jul 2005 15:03:30 -0300 (ADT) Received: from smtp2.surnet.cl (216.155.73.169) by mr2.surnet.cl (7.0.031.3) id 4259ADFA013C28B3; Thu, 7 Jul 2005 14:03:19 -0400 Received: from smtp1.surnet.cl (smtp1.surnet.cl []) by mr2.surnet.cl ([216.155.73.169]); Thu, 07 Jul 2005 18:03:19 +0000 Received: from cluster.surnet.cl (216.155.73.164) by smtp1.surnet.cl (7.0.031.3) id 42587C6E00F4912C; Thu, 7 Jul 2005 14:02:54 -0400 Received: from alvh.no-ip.org (200.85.217.230) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 42B3EF60002BAC6E; Thu, 7 Jul 2005 14:03:30 -0400 Received: by alvh.no-ip.org (Postfix, from userid 1000) id 8FA65C2DC70; Thu, 7 Jul 2005 14:03:29 -0400 (CLT) Date: Thu, 7 Jul 2005 14:03:29 -0400 From: Alvaro Herrera To: mail TechEvolution Cc: pgsql-sql@postgresql.org Subject: Re: getting back autonumber just inserted Message-ID: <20050707180329.GA11332@alvh.no-ip.org> References: <42CD6B58.6060508@techevolution.be> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <42CD6B58.6060508@techevolution.be> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.39 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, FORGED_RCVD_HELO, RCVD_IN_NJABL_PROXY X-Spam-Level: * X-Archive-Number: 200507/40 X-Sequence-Number: 22018 On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote: > hello > > i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 > (windowsinstaller) on a xp prof platform > > i would like to get back the autonumber from the last record inserted, > for other SQL db (m$ sql db ...) i could use: > SELECT @@ IDENTITY > > can someone help me by informing me what the SQL syntax is to be used > with PostGreSQL db and get the same result, the last autonumber inserted? You use the currval() function, using the name of the involved sequence as parameter. There is a pg_get_serial_sequence() function, to which you give the table name and column name, and it will give you the sequence name. -- Alvaro Herrera () Oh, oh, las chicas galacianas, lo harán por las perlas, ˇY las de Arrakis por el agua! Pero si buscas damas Que se consuman como llamas, ˇPrueba una hija de Caladan! (Gurney Halleck)