Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-bugs by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group