Subject | Re: Constraint Irregularity |
---|---|
Author | Adam |
Post date | 2006-03-19T04:56:04Z |
--- In firebird-support@yahoogroups.com, Jason Dodson <jasond@...> wrote:
world too and although I suggest you should review this weakness in
the future, it has nothing to do with your issue.
Look at your constraint
MyField <> ''
NULL means "Unknown Value", so in the cases where MyField is NULL, you
are evaluating
NULL <> ''
which means
"Unknown Value" is different to ''
The above statement can not be true so it returns false. Incidentally,
reversing it would be the same issue.
NULL = ''
would mean
Unknown Value is equal to ''
Which is still a statement that is not true.
all a correct interpretation of the SQL standard. (I have not checked
if every nuance is correct)
Stop thinking that NULL is just another value and treat it as a field
state and it makes more sense. Google for the Firebird NULL guide for
more info.
Adam
>varchar field I had. If I declare a check constraint:
> Ok, first thing, DON'T ask me WHY I am doing this.
>
> Anyway, I found a peculiarity with adding a check constraint to a
>or a real value. The problem is, trying to insert a
> Alter Table MyTable
> Add Constraint MyConstraint Check (MyField <> '');
>
> Seems simple enough. I want no empty stings in this field. Only NULL
> NULL into MyField will cause a constraint violation... like it, forthat moment, can't tell the difference between a
> NULL and an empty string.You know my opinion of this. Of course I also understand the real
world too and although I suggest you should review this weakness in
the future, it has nothing to do with your issue.
Look at your constraint
MyField <> ''
NULL means "Unknown Value", so in the cases where MyField is NULL, you
are evaluating
NULL <> ''
which means
"Unknown Value" is different to ''
The above statement can not be true so it returns false. Incidentally,
reversing it would be the same issue.
NULL = ''
would mean
Unknown Value is equal to ''
Which is still a statement that is not true.
> Now if I modify the check constraint to look like this:the supplemental "or MyField is Null". Any incite
>
> Alter Table MyTable
> Add Constraint MyConstraint Check (MyField <> '' or MyField Is Null);
>
> Everything works peachy. Obviously it is unclear as to why I need
> would be appreciated. If it turns out to be a bug, Ill file a report.It is the Firebird behaviour with respect to nulls and for most if not
all a correct interpretation of the SQL standard. (I have not checked
if every nuance is correct)
Stop thinking that NULL is just another value and treat it as a field
state and it makes more sense. Google for the Firebird NULL guide for
more info.
Adam