4 ms·
It’s a stated [0] goal of the project: > SQLite strives to be flexible regarding the datatype of the content that it stores. [0]: https://sqlite.org/stricttab
by poidos 3mo ago
It’s a stated [0] goal of the project:
> SQLite strives to be flexible regarding the datatype of the content that it stores.
[0]: https://sqlite.org/stricttables.html https://sqlite.org/stricttables.html
- masklinn 3mo agoYou can be flexible with strict tables, type every column as ANY and you pretty much get back the original behaviour.
- poidos 3mo agoSure, but you lose the representation of the developer’s intention that way. I would be pretty pissed off if I inherited a project and the schema was all ANYs.
- masklinn 3mo agoThe intent of ANY is obviously that the values be flexible. That’s why it’s there if you need it.
- drdexebtjl 3mo ago“I intended this to be an integer but it could really be anything” is not very useful.
- poidos 3mo agoSure it is. If you encounter something that’s not an int, that could be a signal you have a bug in your writers. Or in the source of the data. That’s useful information compared to “oh, I have some ints and some strings, that’s ANY, everything is ok.”
- FridgeSeal 3mo ago> If you encounter something that’s not an int, that could be a signal you have a bug in your writers Which, is something you could have caught before it got written at all if you had your db enforcing your types.
- nvdc 3mo agoi have no idea why this would be preferable to failing immediately on write
- InsideOutSanta 3mo agoThe developer's intention is that anything can go in there. You would only inherit a project where everything was ANY if anything could go anywhere. With SQLite's default behavior, anything can always go anywhere, so the type definitions are at best semi-accidentally observed by the code, and at worst completely misleading. You have no idea which of the two the developer intended. I get the impression that this SQLite behavior is a historical oddity caused by the original use case for the tool, rather than something that was intentionally planned and thought through, and was later retconned to be intentional and benign. To me, it makes no sense, even after reading the explanation on sqlite's website.
- jrapdx3 3mo agoIIRC SQLite originated as a Tcl extension. In Tcl at the user level "everything is a string" or a number. So it's logical SQLite would accept values as a string or number. Interestingly a Tcl function defines its own semantics, an input value means whatever the function says it means, perhaps a timestamp. SQLite inherited these attributes, and as many commenters observe, SQLite largely continues to work that way. Implies documentation is crucial. Fortunately SQLite's documentation is among the best out there.
- bhaak 3mo agoBut why aren't you pissed at a database where the columns have types that aren't enforced?
- krior 3mo agoBut that is still better than getting a table with typed columns that have been used like ANY columns.
- tehlike 3mo agoPostgres is flexible, too. Sometimes design choices are just bad, and it's ok.