Skip site navigation (1) Skip section navigation (2)

Re: freezing a particular field in a table

From: hubert depesz lubaczewski <depesz(at)gmail(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: fmiddleton(at)verizon(dot)net, pgsql-admin(at)postgresql(dot)org
Subject: Re: freezing a particular field in a table
Date: 2005-11-24 07:38:47
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
On 11/23/05, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
>   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.

thanks - i didn't know about this operator.

> CREATE TRIGGER impossible_to_change BEFORE UPDATE ON some_table FOR EACH
> > 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.

i would rather use before anyway.
the problem with after is that in aftrer - all you can do is to raise
exception. while - if you would like to value to stick - you would ahve to
change the code *and* change trigger declaration. putting it in before
solves the problem.
of course there might be problem with another triggers, but that's another


In response to

pgsql-admin by date

Next:From: Johnson ZhaoDate: 2005-11-24 10:02:44
Subject: Problems when initdb on WinXP with SP2.
Previous:From: Michael FuhrDate: 2005-11-23 17:55:22
Subject: Re: freezing a particular field in a table

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group