simple rule question

From: Neil Conway <nconway(at)klamath(dot)dyndns(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: simple rule question
Date: 2001-05-12 04:29:46
Message-ID: 20010512002946.A287@klamath.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Snow 2001-05-12 06:14:33 RE: simple rule question
Previous Message Justin Clift 2001-05-12 04:17:19 Would like suggestions of places that support PostgreSQL for Hosting