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

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 (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-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

pgsql-bugs by date

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

pgsql-general by date

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

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