SQLite - (Data Type|Affinities)

1 - About

In SQLite:

  • data types are per-value, not per-column.
  • Columns have “affinities”. The type affinity of a column is the recommended type for data stored in that column. The type is recommended, not required.

Any column can store any type of data. It is just that some columns, given the choice, will prefer to use one storage class over another.

Inserted Integers are stored as integers regardless of the column type.

For instance:

  • a text column that gets passed a numeric string should store it as text, preserving the formatting (decimal places, etc).
  • a numeric column that is passed a numeric string will convert it to a number before storing it, so “10.00” would be later returned as just “10”.

3 - Example

create table test("col1" DOUBLE PRECISION);
PRAGMA table_info(test)
insert into test values (2);
insert into test values ("2");
insert into test values ("t");
select typeof(col1) from test3;
select sum(col1) from test3;

4 - (Data Type|Affinities)

  • TEXT
  • NUMERIC
  • INTEGER
  • REAL
  • BLOB

Date is not an affinity but a numeric from epoch.

5 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap