X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 22DF7D1C516 for ; Fri, 8 Aug 2003 21:12:43 +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 81230-02 for ; Fri, 8 Aug 2003 18:11:16 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id D83F2D1C4C8 for ; Fri, 8 Aug 2003 18:12:31 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h78LCV1m000726 for ; Fri, 8 Aug 2003 21:12:31 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h78L1Aak097681 for pgsql-sql@postgresql.org; Fri, 8 Aug 2003 21:01:10 GMT From: "Prasanth" X-Newsgroups: comp.databases.postgresql.sql References: Subject: Re: Retrieving tuple data on insert Lines: 32 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <84UYa.3431$vK4.1253@fe05.atl2.webusenet.com> X-Complaints-To: abuse@usenetserver.com X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly. Date: Fri, 8 Aug 2003 16:01:30 -0500 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/83 X-Sequence-Number: 14699 you can retrieve it using the currentVal function on the sequence used to generate that id. "sebmil" wrote in message news:pan.2003.07.24.03.59.01.164717@invalid.mail... > Hello, > > I have a table with two columns, created with : CREATE TABLE test ( id > serial primary key, name text ) ; > > To populate the table i use : > INSERT INTO test(name) values('test1'); so the "id" is automatically set > by PostgreSQL. > > Now the problem, i would like to retrieve the value of "id" that > PostgreSQL assigns to this tuple, but i can't make a SELECT on the name i > just inserted because it's not UNIQUE, so SELECT may return multiple > results. > > Is there a way to retrieve the value of "id" from the insertion ? > > I was thinking of something with Oids, like getting the Oid of the INSERT > statement then use it to SELECT the tuple, but i didn't find what to do > with an Oid in PostgreSQL documentation. > > Also, it would be better if it was possible in only one operation (not > INSERT then SELECT). > > Thanks in advance.