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

Re: BUG #4620: Unexpected(doc'd) side effects of using serial and rules

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Simon Keen" <simon(dot)keen(at)eglimited(dot)co(dot)uk>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4620: Unexpected(doc'd) side effects of using serial and rules
Date: 2009-01-18 16:35:19
Message-ID: 2744.1232296519@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
"Simon Keen" <simon(dot)keen(at)eglimited(dot)co(dot)uk> writes:
> I have used serial columns as primary keys in some tables.  I have a rule
> that on insert to a table inserts in another table.  However, the rule
> appears to cause the seq nextval() to be invoked multiple times thus
> destroying any value in NEW.serial_col.

This is a well-known issue arising from the fact that a rule is really a
macro: multiple references to any expression in the original statement
result in multiple evaluations of that expression.

By and large, the best way to propagate inserted information to other
tables is with a trigger.

			regards, tom lane

In response to

Responses

pgsql-bugs by date

Next:From: Rizwan AkbarDate: 2009-01-19 06:22:44
Subject: BUG #4621: Password is shown on the terminal
Previous:From: Simon KeenDate: 2009-01-18 09:19:24
Subject: BUG #4620: Unexpected(doc'd) side effects of using serial and rules

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