Subject Re: [firebird-support] null in triggers
Author Ivan Prenosil
> From: "Paul Vinkenoog"
> > if (New.Quantity <> Old.Quantity) or
> > ((New.Quantity is null) and (Old.Quantity is not null)) or
> > ((New.Quantity is not null) and (Old.Quantity is null))
>
> You can make this shorter:
>
> if not ( New.Quantity = Old.Quantity
> or
> New.Quantity is null and Old.Quantity is null )

Wrong.

...
> PS:
> Shortest general field equality test (with NULL considered equal to
> NULL) that I've been able to come up with is:
>
> A = B or A is null and B is null
>
> or with parens:
>
> ( A = B ) or ( A is null and B is null )

If A is regular value and B is NULL, the result will be NULL ...

> The shortest inequality test is just the negation of this:
>
> not ( A = B or A is null and B is null )

... and hence negation of null is also NULL !!


It is possible to write e.g.

IF ( New.Quantity = Old.Quantity OR New.Quantity is null and Old.Quantity is null )
THEN ... equal
ELSE ... not equal

but you can't reduce it into

IF (NOT ( New.Quantity = Old.Quantity OR New.Quantity is null and Old.Quantity is null ))
THEN ... not equal


Ivan Prenosil
http://www.volny.cz/iprenosil/interbase