SQLite | SQLite Functions | Returning the Data Type of a Stored Value (typeof Function)

The typeof function identifies the data type of a value stored in a table. This article explains how to use the function.

Using the typeof Function

The typeof function identifies the data type of a value. Its syntax is as follows.

typeof(value)

In SQLite, the declared data type of a table column and the data type of the value actually stored in it must be considered separately. For more information, see Data Types.

The typeof function returns a string that identifies the value’s data type. The result is one of integer, real, text, blob, or null. When a column name is supplied, the function returns the data type of the value stored in that column.

Let’s try an example. First, create the following table.

create table test (id integer, data none);
sqlite> create table test (id integer, data none);
sqlite> 

Add the following data with INSERT statements.

insert into test values (1, 3);
insert into test values (2, 15.24);
insert into test values (3, 'Peach');
insert into test values (4, NULL);
insert into test values (5, zeroblob(2));
sqlite> insert into test values (1, 3);
sqlite> insert into test values (2, 15.24);
sqlite> insert into test values (3, 'Peach');
sqlite> insert into test values (4, NULL);
sqlite> insert into test values (5, zeroblob(2));
sqlite> 

Use the typeof function to identify the data types of the values stored in the data column.

select data, typeof(data) from test;
sqlite> .mode column
sqlite> .header on
sqlite> 
sqlite> select data, typeof(data) from test;
data        typeof(data)
----------  ------------
3           integer     
15.24       real        
Peach       text        
            null        
            blob        
sqlite> 

The data type of each value stored in the column is displayed.