Re: update in triggers

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: Jamie Deppeler <jamie(at)doitonce(dot)net(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: update in triggers
Date: 2005-01-19 12:31:52
Message-ID: 41EE5338.8000909@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jamie Deppeler wrote:
> Trigger
> CREATE TRIGGER "new_trigger" AFTER INSERT OR UPDATE
> ON "chargeratetest" FOR EACH ROW
> EXECUTE PROCEDURE "chargeratetest"();
>
>
> function
>
> CREATE OR REPLACE FUNCTION "chargeratetest" () RETURNS trigger AS'
> begin
>
> UPDATE chargeratetest
> set notes=''hello''
> where new."primary" = chargeratetest."primary";
>
> return null;
> end;
> 'LANGUAGE 'plpgsql' IMMUTABLE CALLED ON NULL INPUT SECURITY INVOKER;

If you're only going to modify the updated/inserted record, you should
definitely take a look at RULEs (Chapter 34). They RULE for this kind of
thing ;)

I haven't used them yet, as I only knew about triggers until recently,
but you could do something like this:

CREATE RULE new_rule AS ON UPDATE
TO chargeratetest
DO INSTEAD
UPDATE chargeratetest
SET notes = 'hello'
WHERE primary = NEW.primary;

Alban.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2005-01-19 13:02:46 PostgreSQL 8.0.0 Released
Previous Message Richard Huxton 2005-01-19 12:23:50 Re: Postgres crashed when adding a sequence column