From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Joe Carlson" <joe(at)fruitfly(dot)org> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #1175: insert rule action with defaults |
Date: | 2004-06-22 02:14:53 |
Message-ID: | 9196.1087870493@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> [ double evaluation of serial-column default with ]
>
> create rule silly_insert_r as on insert to silly do
> insert into action (item_id,whence)
> values (new.id,'now');
The standard answer to this is "use a trigger, not a rule, to copy
inserted or updated data to another table". A rule is basically a
macro and as such has the usual multiple-evaluation hazards that
all C programmers are familiar with :-(. There are times when this
behavior is just what you want, but not when trying to copy the
results of volatile expressions.
People are often scared away from triggers because of the apparent
notational complexity. This is too bad, because conceptually triggers
are *much* simpler than rules. Someday I'd like to rewrite the docs
so that triggers are discussed first and made to look like the simpler
facility ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 2004-06-22 06:42:44 | Re: BUG #1164: Informix compatibility ecpg |
Previous Message | PostgreSQL Bugs List | 2004-06-21 23:30:51 | BUG #1175: insert rule action with defaults |