Re: Default values, inserts, and rules...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sean Chittenden <sean(at)chittenden(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: Default values, inserts, and rules...
Date: 2002-08-22 05:28:57
Message-ID: 5888.1029994137@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

Sean Chittenden <sean(at)chittenden(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2002-08-22 07:19:10 Bug #741: postgresql and cygwin
Previous Message Sean Chittenden 2002-08-22 04:41:49 Re: Default values, inserts, and rules...

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2002-08-22 06:10:27 Re: [ADMIN] How to execute my trigger when update certain columns
Previous Message Philip Hallstrom 2002-08-22 05:04:34 Re: Primary Keys