I have a column defined as character varying(20). But it is accepting more than 20 characters. I've already searched but couldn't find anything about it (maybe I'm searching wrong). Has anyone experienced this problem and knows the cause and/or fix?
1 Answer
This is Working As Designed™
SQLite is flexible with regard to datatypes. Datatypes are advisory rather than mandatory.
[...] SQLite allows you to store a 2000-character string into a column of type VARCHAR(50). Other SQL implementations would either throw an error or truncate the string. SQLite stores the entire 2000-character string with no loss of information and without complaint.
It will even happily store a string in a column declared as INTEGER
.
-
Thank you very much! I'm still starting to learn about this database. Just to complement people who may have this question in the future, according to the documentation from version 3.37.0 onwards, the strict option can be used when creating the table so that the data types are considered sqlite.org/stricttables.html (older versions too, but there is an extra detail in the documentation)– FranSCommented Oct 2, 2023 at 14:44