Hacker News new | ask | show | jobs
by eddd-ddde 932 days ago
I don't find this behaviour crazy or unexpected at all.

NULL doesn't refer to any specific 'missing value' state, instead it represents a larger group of possible values of which we don't know the actual value.

So in a pile of values 'foo' and 'bar', NULL could mean either of them, so there is no way of knowing if a NULL row is foo or if it is bar. We can't even know if two NULLS are equal.

4 comments

This reads like you have worked with SQL a lot and has a skewed perspective. As a newcomer to SQL, this could be very surprising given that this diverges from every language that Im aware of having nulls.

    SELECT * FROM Foobar WHERE Val = NULL;
no results

I'm admittedly still learning SQL, but I'm very surprised by this.

The query should be:

    SELECT * FROM Foobar WHERE Val IS NULL;
Which is why these comparisons should be errors, rather than producing gibberish results. Trinary logic stuffed into Boolean operations is just psychotic
Yeah, I agree. The focus here should be the principle of least surprise so your database works correctly. Throw an error to ensure that unintuitive edge cases are handled explicitly. This is SQL after all. It’s used for business purposes, not to demonstrate elegant type systems built around relational algebra.
Is NULL = 'crazy', True?

If no one would expect NULL != 'crazy' to be True.

That's just intuitive, Null is not the string 'crazy'.