37

In SQLite, when I say:

CREATE TABLE my_table 
(
    my_column VARCHAR 
);

without specifying the size of VARCHAR, what is the default size that is used?

I can't seem to find it at sqlite.org or figure out from my database file.

I know that SQLite doesn't enforce size when trying to stuff varchar(500) into varchar(30), but are there tradeoffs in initial size specification and what are best practices?

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
Turar
  • 1,511
  • 5
  • 17
  • 27

3 Answers3

54

It doesn't matter.

SQLite does not use sizes when declaring the VARCHAR type. In fact, it almost doesn't use the type either.

You can store TEXT in an INT column in SQLite. And SQLite will never truncate a TEXT column.

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
Larry Lustig
  • 49,320
  • 14
  • 110
  • 160
  • Wow does it mean SQLite column stores a pointer to the actual data instead? – lulalala Feb 24 '13 at 07:11
  • 1
    I don't know the exact storage mechanism that SQLite uses (one aspect of the "SQL contract" is that you assume nothing about the underlying storage mechanism) but I expect it uses variable length rows with the TEXT data stored in the row. – Larry Lustig Feb 24 '13 at 13:33
21

From what I can gather, VARCHAR is the same as TEXT

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

Also see http://www.sqlite.org/different.html#flex

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
hlindset
  • 440
  • 2
  • 7
11

In SQLite, Text is the parent of VARCHAR and in the default installation is no different http://www.sqlite.org/datatype3.html.

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
htmldrum
  • 2,431
  • 20
  • 20