DEV Community

Cover image for Do you know that if you're using VARCHAR(10) on SQLite you can store 1-million characters anyway?
Flavio Campelo
Flavio Campelo

Posted on

Do you know that if you're using VARCHAR(10) on SQLite you can store 1-million characters anyway?

📮 Contact 🇧🇷 🇺🇸 🇫🇷

Twitter
LinkedIn


SQLite is typelessness

Yes, it's true! According to SQLite dataypes documentation, except only one exception, you can store any kind of data you want in any column of any table, regardless of the type declared datatype of that column. The only exception are INTEGER PRIMARY KEY columns. So, you can pay attention for that.

Warning for automated testing

If you have automated tests and you think that all of your code is working with SQLite, maybe you should to consider making some tests and running them on your server databases (MSSQL, Oracle, PostgreSql, etc.).

When you use datatypes like CHAR, VARCHAR, BLOB, CLOB all of them will be TEXT datatype having UNRESTRICTED length how you can find here.

(ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit)

Look at this sample:

CREATE TABLE MyTable(
    MyColumn VARCHAR(3)
);
Enter fullscreen mode Exit fullscreen mode

You should keep in mind that it will work differently using SQLite and any other databases. So, if we try this query bellow in a Oracle DB, it won't work.

INSERT 
    INTO    MyTable (MyColumn) 
    VALUES  ("my string with more than 3 characters");
Enter fullscreen mode Exit fullscreen mode

But if you use the same query on a SQLite DB, it will work perfectly.

Conclusion

It's always important to know how a tool works to avoid future problems or, at least, you can ready if they arrive.

I'm here only to share with you some of new things that I find working. I hope that is as important to you as it was for me.

Typos or suggestions?

If you've found a typo, a sentence that could be improved or anything else that should be updated on this blog post, you can access it through a git repository and make a pull request. If you feel comfortable with github, instead of posting a comment, please go directly to https://github.com/campelo/documentation and open a new pull request with your changes.

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay