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 A7DEC329D7A for ; Wed, 22 Sep 2004 17:00:04 +0100 (BST) 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 27016-05 for ; Wed, 22 Sep 2004 15:59:59 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 1928A329D18 for ; Wed, 22 Sep 2004 16:59:58 +0100 (BST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id i8MFxMtn049287 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 22 Sep 2004 09:59:25 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id i8MFxMf7021408; Wed, 22 Sep 2004 09:59:22 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id i8MFxMU9021407; Wed, 22 Sep 2004 09:59:22 -0600 (MDT) (envelope-from mfuhr) Date: Wed, 22 Sep 2004 09:59:22 -0600 From: Michael Fuhr To: Bradley Kieser Cc: pgsql-admin@postgresql.org Subject: Re: Getting the OID of inserted row in a rule Message-ID: <20040922155922.GA12629@winnie.fuhr.org> References: <41517C66.9040709@kieser.net> <20040922152643.GA92429@winnie.fuhr.org> <41519A7E.8050803@kieser.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41519A7E.8050803@kieser.net> 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: 200409/209 X-Sequence-Number: 14912 On Wed, Sep 22, 2004 at 04:30:06PM +0100, Bradley Kieser wrote: > Michael Fuhr wrote: > > >CREATE RULE v_ins AS ON INSERT TO v DO INSTEAD ( > > INSERT INTO a (xxx) VALUES (NEW.xxx); > > INSERT INTO b (col1, col2, col3) VALUES (NEW.col1, NEW.col2, > > currval('a_id_seq')) > >); > > But what if another insert happens in the mean time? Then the sequence > would have advanced that the data will be scrambled. |Given that this > could be a very active dataset, that situation is almost certain to occur. currval() returns the last value returned by nextval() in *this session*. http://www.postgresql.org/docs/7.4/static/functions-sequence.html http://www.postgresql.org/docs/faqs/FAQ.html#4.15.3 Do you have multiple processes or threads sharing the same connection? Perhaps one of the developers can comment on the possibility of a race condition in that case. -- Michael Fuhr http://www.fuhr.org/~mfuhr/