Re: Rule Question

From: Luca Ferrari <fluca1978(at)infinito(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Rule Question
Date: 2013-07-25 13:55:02
Message-ID: CAKoxK+6KaMb+qeENj6eWrF5gGBqQSde8kSR-_6OHDMRrvELsTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jul 25, 2013 at 3:02 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Luca Ferrari <fluca1978(at)infinito(dot)it> writes:
>> The original post was related to the update of b, so I guess it is
>> better to limit the trigger scope to update on such column:
>
>> CREATE OR REPLACE FUNCTION b_mirror() RETURNS TRIGGER AS
>> $mirror$
>> BEGIN
>> NEW.a = NEW.b;
>> RETURN NEW;
>> END;
>> $mirror$ LANGUAGE plpgsql;
>
>> CREATE TRIGGER tr_b_mirror AFTER UPDATE OF b ON cats FOR EACH ROW
>> EXECUTE PROCEDURE b_mirror();
>
>> It is worth noting that the trigger could be an after one,
>
> No, it has to be a BEFORE trigger, else it's too late to affect the
> row value that gets stored.

Ops..I wrote it without my brain with me: of course it has to be a before one.

Thanks,
Luca

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2013-07-25 14:10:45 Re: Why are stored procedures looked on so negatively?
Previous Message V S P 2013-07-25 13:33:17 Re: Why are stored procedures looked on so negatively?