16
The question has a slightly more conceptual bias, so I’m going to use a simple generic example.
There are cases where some column may be in a special situation, this because an information:
- is not available,
- is invalid at any time,
- is unknown,
- is undetermined,
- has no relevance,
- may be in a special situation that only makes sense for the domain specific.
One of the ways of indicating the special situation is to use of null
, which is already questionable whether it is something good or bad, although everything has its merit in certain circumstances. The use of null
is a clear case of choosing unnatural special values to the domain of the column to indicate one special situation.
But you may need to indicate more precisely what the special situation is, the reason for the current state. In question about the null
there is a definition of how to solve a special situation. But there may be more than one reason, and worse, it may be that new reasons are included in the future.
For example, in an academic control there is a column with students' grades in disciplines may not be enough to have a zero grade. A zero note not the same as no note. And a null
It may not be enough since it only indicates that there is no grade. You need to know why there is no note, since each circumstance may require a different treatment. You need to know if the note:
- has not yet been given,
- does not exist because the student is excused from that evaluation,
- he did not make the assessment (which in this case is different from him having zero grade).
I know that in some cases we can avoid that there are certain reasons improving the normalization. That’s not the point here.
There are basically two solutions to treat this:
- Documents that certain values are considered as these reasons (e.g., values above 10 or negative in a note are special situations broken down into each of these values outside the normal range in the example
-1
would indicate the reasona
quoted above,-2
the reasonb
and-3
for the reasonc
). - An auxiliary column is used to indicate the reason for the special situation (Ex.: there will be an indication of the reasons a, b or c cited above, and of course the indication that the note is valid and should be considered normally, even if it is zero).
In a domain with special situation we should use auxiliary values or columns to indicate the situation? That is, there is more perks in one than the other? Particularly prefer the second.
How to deal with these cases? After all, darlings can give wrong results without considering these cases. And this holds for either of the two options.
A typical example of the problem is the calculation of the average values of selected lines. But all the problems that involve null
, also apply in this case. Database systems often have a solution to deal with the null
.
Bonus point: is there a way to abstract (make transparent) this? Or the user (maybe a developer) will have to know this need and handle it properly in each query?
You turned my head. I didn’t understand anything you wanted to know.
– Jorge B.
@Jorgeb. Do you understand the subject I’m talking about? If you have any specific questions, can I try to help clarify it for you.
– Maniero
Yes I understand, then I read better at home and say something. Meanwhile I delete these comments.
– Jorge B.
I would like to understand why you are considering the very broad question.
– Maniero
@Jorgeb. If I understand correctly, the crux of the question is we should use auxiliary values or columns to indicate the situation? "The situation" being that a
NULL
can represent several things.– bfavaretto
I also did not notice the bigown too ample, nor any other reason for closure. Sometimes I think people don’t even read the questions.
– Jorge B.
@bfavaretto is this, but obviously I want the reason and not a simple "this or that". I don’t want a chapter in a book, I don’t want multiple answers where anyone can be right. A simple explanation of why to use one or the other option. It’s very similar to the question about the null which was not considered broad.
– Maniero
@Jorgeb. It’s true. If you really have a problem, I’m willing to improve it. I just need to understand what, 'cause I may have failed, but I worked really hard not to leave her in trouble.
– Maniero
I read the question several times and didn’t really understand it. I didn’t have time to comment on why I didn’t understand, so I voted to close. Now with the editions, with the example of the student’s note and the answer of @Bacco I understood the question perfectly. Vote to close withdrawn.
– Franchesco
The use of null in optional fields also fits in special situations? For example I have a scheme with tables 'Question' and 'Choice', but when the user answers he can make a free answer. When his answer is 'free' the choice is null, or when he chooses a 'choice' his free answer is null. Following the reasoning of the question, I could put another value in the place of null, for example, 'does not apply'... It would really be nice if it were abstracted.
– Franchesco
@Earendul When you only need to indicate exists or not, the
null
solves well, even in one more column. That is when you have only one special situation for the domain of that column. The fact that you have a special situation in another column, is a separate problem. I understood that they are mutually exclusive, but there is still only one reason for the absence of value in each column. There are no two reasons for the same column.– Maniero
@Earendul Not understanding a question is an excellent reason to not vote to close. Others may have (and seem to have) understood. In these cases, ask for clarification in the comments. Vote to close as "not clear" when relevant information is missing from the question.
– bfavaretto
@bfavaretto - I get it, I just failed to be too hasty, I really could have waited for more details before voting. It won’t happen again...
– Franchesco
I think that this is a very broad question that depends on the analysis of each situation and that there will be no right or wrong
– Fábio Lemos Elizandro