Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the best SQLite data type for a long string

Tags:

sql

sqlite

In SQLite3 I am going to be storing a very long string that looks something like this:

string linkList = "www.blah.com,www.meh.com,www.hah.com";  

will definitely exceed 255 chars, will probably be over 1000 chars

Should the column linkList be a varchar, TEXT or something else to store a string that will probably be longer than 1000 chars

CREATE TABLE(uId INT PRIMARY KEY, linkList varchar); 

What would be the best variable type to use for the column linkList?

like image 383
sazr Avatar asked Mar 18 '12 03:03

sazr


People also ask

How long can text be in SQLite?

SQLite text and BLOB values are always variable length. The maximum size of a text or BLOB value is limited by a compile-time directive. The default limit is exactly one billion bytes, or slightly less than a full gigabyte.

Does SQLite support long?

INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. Since long is 8 byte and INTEGER can also save values of 8 bytes, you can use INTEGER .

What is the maximum size of a varchar in SQLite?

(9) What is the maximum size of a VARCHAR in SQLite? SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact.


2 Answers

You should use TEXT.

Although, that's the same thing as VARCHAR:

If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity

And also:

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

"SQLite does not impose any length restrictions"

like image 85
Jordão Avatar answered Sep 26 '22 01:09

Jordão


Actually, all data types in SQLite is no matter, all data will be stored as strings. You can execute query CREATE TABLE(uId INT PRIMARY KEY, linkList BlahBlahString); without any error. Data type in SQLite is for sql compability only

like image 45
krevedko Avatar answered Sep 22 '22 01:09

krevedko