top | item 42652083

(no title)

lolpanda | 1 year ago

I actually like how NULLs behave in SQL. They mean "I don't know" In the modern programming language we all care about Null safety. But no matter how you model your data, you will always run into the situations when you don't know everything. So I believe NOT NULL is not very practical. NULLs in SQL handle these case very well - when the input is unknown your output is unknown

discuss

order

int_19h|1 year ago

Except they don't consistently behave that way. If NULL means "unknown", why do they show up in outer joins, or when you SUM an empty table?

cglace|1 year ago

The most annoying is having to order by DESC NULLS LAST to get the largest value from an aggregation.

dalton_zk|1 year ago

I feel like the same, Null equal null is null is totally right

afiori|1 year ago

I feel like a select for:

- col1 = 1 should not return NULLS

- !(col1 = 1) should return NULLS

- col1 <> 1 should not return NULLS

kijin|1 year ago

Agreed. If SQL didn't have NULL, we'd have other special values meaning "I don't know" or "no data" all over the place.

Too many newbies hear that NULL is bad, so they declare all columns as NOT NULL and end up inserting ad hoc values like 0, -1, '', or {} when they inevitably come across cases where they don't have data. Which is even worse than NULL.