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