pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Bradley Kieser <brad@kieser.net>
Cc: pgsql-admin@postgresql.org
Subject: Re: Getting the OID of inserted row in a rule
Date: Wed, 22 Sep 2004 09:59:22 -0600
Message-ID: <20040922155922.GA12629@winnie.fuhr.org> (raw)
In-Reply-To: <41519A7E.8050803@kieser.net>
References: <41517C66.9040709@kieser.net>
	<20040922152643.GA92429@winnie.fuhr.org>
	<41519A7E.8050803@kieser.net>

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/



view thread (6+ messages)  latest in thread

Message-ID: <20040922155922.GA12629@winnie.fuhr.org>
Permalink:  ../20040922155922.GA12629@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20040922155922.GA12629@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mike@fuhr.org, brad@kieser.net
  Subject: Re: Getting the OID of inserted row in a rule
  In-Reply-To: <20040922155922.GA12629@winnie.fuhr.org>
  References: <41517C66.9040709@kieser.net> <20040922152643.GA92429@winnie.fuhr.org> <41519A7E.8050803@kieser.net> <20040922155922.GA12629@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox