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 7603A3A5292 for ; Mon, 22 Nov 2004 14:59:21 +0000 (GMT) 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 53159-01 for ; Mon, 22 Nov 2004 14:58:32 +0000 (GMT) Received: from smtp.tor.pathcom.com (smtp.tor.pathcom.com [209.250.128.26]) by svr1.postgresql.org (Postfix) with ESMTP id A55973A5200 for ; Mon, 22 Nov 2004 14:58:34 +0000 (GMT) Received: from sinope.axxent.ca (v44.wall.tor.axxent.ca [209.250.131.204]) by smtp.tor.pathcom.com (8.12.10/8.12.6) with ESMTP id iAMEwYsw030380; Mon, 22 Nov 2004 09:58:34 -0500 Received: by sinope.inside.pathcom.com with Internet Mail Service (5.5.2653.19) id ; Mon, 22 Nov 2004 09:58:33 -0500 Message-ID: From: "Passynkov, Vadim" To: "'Erik Thiele'" , "Passynkov, Vadim" Cc: pgsql-sql@postgresql.org Subject: Re: get sequence value of insert command Date: Mon, 22 Nov 2004 09:58:29 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/230 X-Sequence-Number: 19549 > > > create sequence mysequence; > > > > > > create table foo( > > > id integer default nextval('mysequence'), > > > bla text, > > > wombat integer, > > > foobar date, > > > primary key(id) > > > ); > > > > > > insert into foo (wombat) values (88); > > > > > > now how do i know the id of my newly inserted element? and > > > how can this be done in a completely concurrency safe way? > > > > CREATE RULE get_pkey_on_insert AS ON INSERT TO foo DO SELECT > > currval('mysequence') AS id LIMIT 1; > > now that one is really great! you should definitly add it to the > faq. plus an additional explanation why the limit 1 is needed here. INSERT INTO foo ( ... ) ( SELECT * FROM foo1 ); > > thanks! > erik > -- Vadim Passynkov