Re: BUG #1175: insert rule action with defaults - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1175: insert rule action with defaults
Date
Msg-id 9196.1087870493@sss.pgh.pa.us
Whole thread Raw
In response to BUG #1175: insert rule action with defaults  ("PostgreSQL Bugs List" <pgsql-bugs@postgresql.org>)
Responses Re: BUG #1175: insert rule action with defaults
List pgsql-bugs
"PostgreSQL Bugs List" <pgsql-bugs@postgresql.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

pgsql-bugs by date:

Previous
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1175: insert rule action with defaults
Next
From: Michael Meskes
Date:
Subject: Re: BUG #1164: Informix compatibility ecpg