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 A6C4C329C6B for ; Wed, 22 Sep 2004 17:15:31 +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 35438-01 for ; Wed, 22 Sep 2004 16:15:29 +0000 (GMT) Received: from laptop.kieser.net (unknown [195.166.116.245]) by svr1.postgresql.org (Postfix) with ESMTP id 6806F329C67 for ; Wed, 22 Sep 2004 17:15:28 +0100 (BST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by laptop.kieser.net (Postfix) with ESMTP id 327E419480; Wed, 22 Sep 2004 17:15:40 +0100 (BST) Message-ID: <4151A52C.5030500@kieser.net> Date: Wed, 22 Sep 2004 17:15:40 +0100 From: Bradley Kieser User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) X-Accept-Language: en, en-us MIME-Version: 1.0 To: Michael Fuhr Cc: pgsql-admin@postgresql.org Subject: Re: Getting the OID of inserted row in a rule References: <41517C66.9040709@kieser.net> <20040922152643.GA92429@winnie.fuhr.org> <41519A7E.8050803@kieser.net> <20040922155922.GA12629@winnie.fuhr.org> In-Reply-To: <20040922155922.GA12629@winnie.fuhr.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/211 X-Sequence-Number: 14914 Ah! I didn't know that! Michael, thank you so much! No, I don't have anything sharing these sessions, they are rules in the back end so they should (unless someone tells me differently) AFAIK be in their own threads. Top man! Brad Michael Fuhr wrote: >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. > > >