Re: double insert on inherited table with where constraint based on sequence

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andrew Hammond" <andrew(dot)george(dot)hammond(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: double insert on inherited table with where constraint based on sequence
Date: 2006-07-19 19:22:01
Message-ID: 15218.1153336921@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Andrew Hammond" <andrew(dot)george(dot)hammond(at)gmail(dot)com> writes:
> Rules:
> t2_part AS
> ON INSERT TO t2
> WHERE new.id > 10 DO INSTEAD INSERT INTO t2_child (id, name)
> VALUES (new.id, new.name)

"new.id" is replaced by "nextval('t2_id_seq'::regclass)" each time it
appears ... which will be four separate times, viz the two evaluations
of the WHERE clause and the two VALUES clauses.

Basically, volatile functions and rules do not mix. Consider using
a trigger on t2 instead to redirect the insert somewhere else.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Marius Žalinauskas 2006-07-19 19:26:45 Re: BUG #2535: Unicode on Windows: aogonek is not distinguished from agrave
Previous Message Andrew Hammond 2006-07-19 18:14:13 double insert on inherited table with where constraint based on sequence