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