Remix.run Logo
PittleyDunkin 3 days ago

> SQLite also always had a null type, surely?

NULL is surely a value, not a type, no? You can restrict use of NULL with the column type, but it doesn't make any sense to have a NULL type rather than, say, a nullable-string type. What would be the point?

IshKebab 3 days ago | parent [-]

Null/none is a value and a type. E.g. in Python there's None which has the type NoneType. Sometimes they are named the same.

This is an example of a singleton type - a type that can only hold one value. It's not the only example though, it's fairly common to support string or integer singleton types, e.g. in Typescript you can have the type "foo" which only has a single possible value, "foo". Or some languages support a type int(5) for which the only possible value is 5.

You might think that's useless, but it's very useful when combining types, e.g. via unions. Or sometimes when writing generic code.

SQL has an extremely primitive type system so there's no syntax for type unions etc. But you can imagine if it was written by someone who had experience of modern typing you would say `my_nullable_column: string | null`.

PittleyDunkin 3 days ago | parent [-]

Ok, but you could also just say "nullable string". Giving null a type doesn't seem to yield a benefit outside of python. Especially when, again, it doesn't appear to have any utility in SQL outside of applying to types.