X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2841952994 for ; Tue, 16 Aug 2005 18:35:26 -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 10360-06 for ; Tue, 16 Aug 2005 21:35:24 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by svr1.postgresql.org (Postfix) with ESMTP id 70965529A5 for ; Tue, 16 Aug 2005 18:35:23 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i2so34291wra for ; Tue, 16 Aug 2005 14:35:25 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LPVTurWtW9aQNTVrdpcLhHKpC2UlKTYpWsRHjz20Gd9XuLXDucuuifSX58AR1SMMmZlsgGUvIUrY6NbTFdQEN2TyGVDhgU78XWyzlvc3JCR8aIpkhX6g5Xv7tfdG5rdbQ6ibnRTNRzYgKDigD/vbFfRyobO52BzI4In31qDuKP0= Received: by 10.54.46.5 with SMTP id t5mr3391958wrt; Tue, 16 Aug 2005 14:35:25 -0700 (PDT) Received: by 10.54.4.36 with HTTP; Tue, 16 Aug 2005 14:35:25 -0700 (PDT) Message-ID: <9e0a2869050816143527ebc2f4@mail.gmail.com> Date: Tue, 16 Aug 2005 17:35:25 -0400 From: Juan Miguel Paredes To: pgsql-admin@postgresql.org Subject: Re: SQL Help - Obtaining ID of record INSERTED Cc: josh@segrestfarms.com In-Reply-To: <430255F0.7060500@segrestfarms.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <430255F0.7060500@segrestfarms.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=-0.174 required=5 tests=[AWL=-0.198, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/199 X-Sequence-Number: 18518 Greetings, all! As described in http://www.postgresql.org/docs/8.0/interactive/datatype.html#DATATYPE-SERIA= L, column "type" SERIAL is really an integer type with an implicit sequence associated by default with that column. In order to get the last generated value from the sequence, use the "currval" function, as described in http://www.postgresql.org/docs/8.0/interactive/functions-seque= nce.html. Hope this helps! On 8/16/05, josh@segrestfarms.com wrote: > Greetings. >=20 > INSERT INTO > orderstemp (customerid,datecreated) > VALUES > ('5443','8/16/2005 12:00PM') >=20 > The table orderstemp has a unique identifier field, orderid (of type > SERIAL). >=20 > How can I obtain the orderid of the record inserted in the INSERT INTO > statement in postgresql? >=20 > MSSQL does it like this: >=20 > INSERT INTO > orderstemp (customerid,datecreated) > VALUES > ('5443','8/16/2005 12:00PM') > SELECT @@identity as orderid >=20 > but this doens't work in postgresql. >=20 > Any ideas? Thanks in advance. >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >