From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Neil Conway <nconway(at)klamath(dot)dyndns(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: simple rule question |
Date: | 2001-05-12 16:55:21 |
Message-ID: | 9920.989686521@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Neil Conway <nconway(at)klamath(dot)dyndns(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-05-12 17:15:17 | Re: about new join syntax performance |
Previous Message | David Stevenson | 2001-05-12 16:00:35 | Question on Starting Postgres for the first time |