Re: simple rule question - Mailing list pgsql-general

From Tom Lane
Subject Re: simple rule question
Date
Msg-id 9920.989686521@sss.pgh.pa.us
Whole thread Raw
In response to simple rule question  (Neil Conway <nconway@klamath.dyndns.org>)
List pgsql-general
Neil Conway <nconway@klamath.dyndns.org> writes:
> I want to create a rule (or a trigger or whatever) so that when
> data is inserted into a certain table, one column of the
> newly inserted row is replaced with the result of a function.

I don't think you can do that with a rule; I see no way to write a
non-circular rule for it.  But it's easy with a trigger.  The trigger
function body would be something like

    new.specialcol := my_function(new.specialcol);
    return new;

and then you'd declare it as a BEFORE INSERT trigger.  (AFTER INSERT
is too late to change the contents of the to-be-inserted row.)

See the manual or past discussions of triggers for the syntactical
details.

            regards, tom lane

pgsql-general by date:

Previous
From: "Gyozo Papp"
Date:
Subject: about new join syntax performance
Next
From: Tom Lane
Date:
Subject: Re: about new join syntax performance