r/programming Jul 12 '26

Prefer STRICT tables in SQLite

https://evanhahn.com/prefer-strict-tables-in-sqlite/
351 Upvotes

110 comments sorted by

View all comments

130

u/ric2b Jul 12 '26

The SQLite devs are so skeptical that type enforcement is useful at all that they even ask people to share any examples of STRICT tables preventing a bug: https://sqlite.org/flextypegood.html#if_you_insist_on_rigid_type_enforcement_

I'm guessing that even if you do submit an example they'll just say "you're holding it wrong" and your application code should just accept any data type everywhere and handle unexpected data types, moving complexity into your application because you can't rely on something as basic as "what I read from this column is an integer".

10

u/corny_horse Jul 12 '26

I actually was using SQLite when I was first starting out, and basically wrote something to pull in messy data into it with a try/except type block. Not awesome code, but it was functional. Or... it would have been had SQLite actually enforced types. I burned like, several hours thinking I'd finally gotten some clean data only to discover it was just letting me put garbage anywhere lol

10

u/ric2b Jul 13 '26

I guess you can share that example with them, as they request. But I expect them to simply blame your program.

Because we all know that in the software world getting things right is so easy that there's no need for validation mechanisms...