Re: freezing a particular field in a table - Mailing list pgsql-admin

From Michael Fuhr
Subject Re: freezing a particular field in a table
Date
Msg-id 20051123175522.GA3828@winnie.fuhr.org
Whole thread Raw
In response to Re: freezing a particular field in a table  (hubert depesz lubaczewski <depesz@gmail.com>)
Responses Re: freezing a particular field in a table
List pgsql-admin
On Wed, Nov 23, 2005 at 10:28:01AM +0100, hubert depesz lubaczewski wrote:
>         IF
>                 (NEW.some_field IS NULL AND OLD.some_field IS NOT NULL)
>                 OR
>                 (NEW.some_field IS NOT NULL AND OLD.some_field IS NULL)
>                 OR
>                 (NEW.some_field IS NOT NULL AND OLD.some_field IS NOT NULL
> AND NEW.some_field <> OLD.some_field)
>         THEN

A more succinct expression would be:

  IF NEW.some_field IS DISTINCT FROM OLD.some_field THEN

IS DISTINCT FROM is like <> except that it treats NULL as an ordinary
value.

> CREATE TRIGGER impossible_to_change BEFORE UPDATE ON some_table FOR EACH ROW
> EXECUTE PROCEDURE impossible_to_change();

If the table has other triggers and you don't want them to modify
the value either, then the check should probably go in an AFTER
trigger.

--
Michael Fuhr

pgsql-admin by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: freezing a particular field in a table
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: freezing a particular field in a table