Re: freezing a particular field in a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux