2

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?

2
  • Please show us your schema insert statement and result. Commented Oct 2, 2023 at 11:44
  • Hi, and welcome to dba.se! A bit more detail here. Commented Oct 3, 2023 at 22:25

1 Answer 1

4

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.

1
  • 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) Commented Oct 2, 2023 at 14:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.