Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the sqlite default column type?

Tags:

sqlite

In one of our company's scripts I found a sqlite create table script that for one of the columns the data type definition is missing. What is the default value of a column type at the time of table creation?

create table x(
y, 
z int
); 

In the above simplified example y column is under question.

When I try to check the column with

pragma table_info(x)

the information for y column is missing.

like image 211
apadana Avatar asked Apr 22 '16 00:04

apadana


People also ask

What is column in SQLite?

Introduction to SQLite generated columns SQLite introduced the generated columns since version 3.31. 0. By definition, generated columns are the columns of a table whose values are derived from an expression that involves other columns of the same table. Generated columns are also known as computed columns.

What is SQLite datatype?

SQLite only has four primitive data types: INTEGER, REAL, TEXT, and BLOB. APIs that return database values as an object will only ever return one of these four types.

Does SQLite have 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. Your content is never truncated. SQLite understands the column type of "VARCHAR(N)" to be the same as "TEXT", regardless of the value of N.

What is difference between text and varchar in SQLite?

Some Differences Between VARCHAR and TEXT The VAR in VARCHAR means that you can set the max size to anything between 1 and 65,535. TEXT fields have a fixed max size of 65,535 characters. A VARCHAR can be part of an index whereas a TEXT field requires you to specify a prefix length, which can be part of an index.


2 Answers

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

3.1. Determination Of Column Affinity

  1. If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity BLOB.

So we can assume that default type is a BLOB.

like image 113
Roman Ivasyshyn Avatar answered Oct 05 '22 10:10

Roman Ivasyshyn


There are no types of a column only a type affinity. In the case it's omitted, the type affinity is NUMERIC. You can read up on it here: https://www.sqlite.org/datatype3.html

like image 21
Daniel A. White Avatar answered Oct 05 '22 12:10

Daniel A. White