Re: Updating - Mailing list pgsql-general

From Daniel Verite
Subject Re: Updating
Date
Msg-id 4e715e28-cdbe-4302-b644-5c14180ff5cb@mm
Whole thread Raw
In response to Re: Updating  (Adrian Klaver <aklaver@comcast.net>)
Responses Re: Updating  (Adrian Klaver <aklaver@comcast.net>)
List pgsql-general
    Adrian Klaver wrote:

> CREATE FUNCTION foo() RETURNS trigger AS
> $Body$
>     BEGIN
>     IF NEW.colname != OLD.colname    THEN
>          ..."Do something"..;
>        RETURN whatever;
>    ELSE
>        RETURN NEW:
>      END IF;
>     END;
> $Body$ LANGUAGE plpgsql;

Beware that the "Do something" code path will not be taken when the
column goes from NULL to non-NULL or non-NULL to NULL.

In the general case where the column is nullable, better use "IS
DISTINCT FROM" instead of inequality:
IF NEW.colname IS DISTINCT FROM OLD.colname

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org

pgsql-general by date:

Previous
From: "Adam Rich"
Date:
Subject: 8.3.0 upgrade
Next
From: luca.ciciriello@email.it
Date:
Subject: Re: LOCK TABLE HELP