Re: Update on tables when the row doesn't change

From: Dawid Kuroczko <qnex42(at)gmail(dot)com>
To: Sebastian Böck <sebastianboeck(at)freenet(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Update on tables when the row doesn't change
Date: 2005-05-25 10:37:57
Message-ID: 758d5e7f05052503371154ef65@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/25/05, Sebastian Böck <sebastianboeck(at)freenet(dot)de> wrote:
> >>CREATE OR REPLACE FUNCTION upd (view_test) RETURNS VOID AS $$
> >> DECLARE
> >> NEW ALIAS FOR $1;
> >> BEGIN
> >> RAISE NOTICE 'UPDATE';
> >> UPDATE test SET test = NEW.test WHERE id = OLD.id;
> >> UPDATE join1 SET text1 = NEW.text1 WHERE id = OLD.id;
> >> UPDATE join2 SET text2 = NEW.text2 WHERE id = OLD.id;
> >> UPDATE join3 SET text3 = NEW.text3 WHERE id = OLD.id;
> >> RETURN;
> >> END;
> >>$$ LANGUAGE plpgsql;
> >
> >
> > Control question, I didn't check it, but would it be enough to change from:
> > UPDATE join1 SET text1 = NEW.text1 WHERE id = OLD.id;
> > to:
> > UPDATE join1 SET text1 = NEW.text1 WHERE id = OLD.id AND text1 <> NEW.text1?
> >
> > ... I may be wrong. :)
>
> Yes, thats more elegant then my other (4th) solution.
> Was late yesterday evening ;)

Be wary of the NULL values though. :) Either don't use them, add
something like 'AND (text1 <> NEW.text1 OR text1 IS NULL OR NEW.text1
IS NULL)' or something more complicated. :)

Regards,
Dawid

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sebastian Böck 2005-05-25 11:09:53 Re: Update on tables when the row doesn't change
Previous Message Sebastian Böck 2005-05-25 09:35:40 Re: Update on tables when the row doesn't change