Hacker News new | ask | show | jobs
by dragonwriter 2960 days ago
> What do you use in a database when you have a field where you literally do not know what the value should be?

You don't.

If a value may not be present for an entity, it's not an attribute of the entity in question, it's an attribute of another entity that has a (0..1):1 relationship to the entity in question.

Normalization eliminates NULL.

1 comments

That's great. Now I do a query. Maybe I use a join. If a row has the "0" case of that (0..1):1 relationship, what do I get?

Or maybe I don't do a join. Maybe I do a separate query. If the query comes back with zero rows, then I... what?

What do I get ? You get what you ask for.

Then I ... what ? Then you do what needs to be done as specified by the business in the case the queried piece of information is unknown.

> What do I get ? You get what you ask for.

In the join case, don't I get a NULL in the row that comes back if there isn't an entry in the other table? Or do I just not get a row?

> Then you do what needs to be done as specified by the business in the case the queried piece of information is unknown.

Sure, but how do I represent that condition in my software? With a different class/structure? With a flag that indicates that the other field isn't valid? Or with a null?

From where I sit, normalization doesn't make the problem go away at all.