Re: [BUGS] Default values, inserts, and rules... - Mailing list pgsql-general

From Tom Lane
Subject Re: [BUGS] Default values, inserts, and rules...
Date
Msg-id 5888.1029994137@sss.pgh.pa.us
Whole thread Raw
In response to Re: [BUGS] Default values, inserts, and rules...  (Sean Chittenden <sean@chittenden.org>)
Responses Re: [BUGS] Default values, inserts, and rules...  (Sean Chittenden <sean@chittenden.org>)
List pgsql-general
Sean Chittenden <sean@chittenden.org> writes:
> What I get from this is that NEW.pk is doing a NEXTVAL() instead of
> reading the value that the tuple was populated with from the sequence.

You are missing the point completely.  Rules do not operate on
individual tuples --- a rule is a textual transformation on the whole
query before it ever gets executed at all.  What gets substituted into
the INSERT command in your rule is not any specific tuple's value,
but the NEXTVAL()-containing expression.

I'm too tired to explain this clearly, but perhaps if you go back and
reread the docs about rules with the above hint in mind, it will make
sense.

My rule of thumb is that if you think you can do it with either a
trigger or a rule, you should be using a trigger.  Triggers are way
easier to understand, even though the notational baggage is heavier.

            regards, tom lane

pgsql-general by date:

Previous
From: Philip Hallstrom
Date:
Subject: Re: Primary Keys
Next
From: Oliver Elphick
Date:
Subject: Re: [ADMIN] How to execute my trigger when update certain columns