simple rule question - Mailing list pgsql-general

From Neil Conway
Subject simple rule question
Date
Msg-id 20010512002946.A287@klamath.dyndns.org
Whole thread Raw
Responses RE: simple rule question  ("Andrew Snow" <andrew@modulus.org>)
Re: simple rule question  (will trillich <will@serensoft.com>)
Re: simple rule question  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi everyone,

This should be easy, but for some reason I can't figure it out.

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.

In order words:

INSERT INTO foo (simple, special) VALUES ('a', 'b');

Should become:

INSERT INTO foo (simple, special) VALUES ('a', my_function('b'));

(Where 'special' is the column that needs to be replaced with
the dynamically generated data, and 'my_function' is the
function I want to be called: note that my_function needs to
be passed the data it is replacing).

Would someone be kind enough to write a rule for me which does
this? All the rules I've tried to write create infinite loops
(since the RULE is defined as ON INSERT, and its action is
doing an INSERT to the same table, which triggers the rule
again).

Thanks in advance,

Neil

pgsql-general by date:

Previous
From: Justin Clift
Date:
Subject: Would like suggestions of places that support PostgreSQL for Hosting
Next
From: "Andrew Snow"
Date:
Subject: RE: simple rule question