Search Postgresql Archives

Re: Updating

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

 



On Monday 17 March 2008 4:54 am, Daniel Verite wrote:
> 	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

Thanks for the heads up. This is a case I usually only remember when I start 
testing the function.
-- 
Adrian Klaver
aklaver@xxxxxxxxxxx

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux