username
username

Reputation: 367

What is exact limits of peewee field types with sqlite database engine used?

I'm starting using peewee with sqlite database engine and have a lot of confusion about what field type should I use. I write now small scripts for myself, so performance is not the issue, but possible data loss due to data type limitations is.

On the official peewee documentation there are lot of types listed though none information about them provided. I wish their limits were provided in more clear way, like w3 did.

I'm conducting various tests now and getting wierd results. Like IntegerField, BigIntegerField and SmallIntegerField actually maps in the same column type (what is the point on make them different then?). CharField maps to VARCHAR(255) but I can store large amounts of text there - is it safe or should be considered as unpredictable behaviour? FixedCharField allows to store large texts as well, but corrupting them without truncating, etc. I was investigating sqlite documentation as well, but there only 5 basic types introduced. Though I clearly see in DB browser For SQLite and in DB Browser extension for PyCharm, that peewee actually uses broader mapping (say, uses VARCHAR not introduced by sqlite) or interpret existing types on it's own way (say, allow to .save() vast variety of values in BooleanField truncating them into 0 or 1).

At the best, I wish to know the exact limits and difference between all 25 field types when using sqlite engine. Though, it would be nice to know just the field types with the largest limits to store integer, floating point, text and arbitrary binary data - in these generalized categories - which should I choose to store the most amount of data safely?

Upvotes: 0

Views: 762

Answers (1)

coleifer
coleifer

Reputation: 26245

Sqlite has just 5 types, text, int, real (float), blob, and null.

Varchar, char, text, etc all are treated as TEXT. Length does not matter.

Integer, smallint, bigint, etc are treated as INT. Sqlite uses 64-bit ints.

Read the Sqlite documentation, it will explain this all:

https://www.sqlite.org/datatype3.html

Upvotes: 0

Related Questions