Name

CAST — Force a type conversion

Syntax

image with no caption

Description

The CAST operator forces the cast expression to the datatype described by type name. The actual representation (integer, real, text, BLOB) will be derived from the type name by searching (case-insensitively) for these specific substrings. The first string that matches will determine the type. If no matches are found, the cast expression will be converted into the most appropriate numeric value.

SubstringDatatype
INTInteger
CHARText
CLOBText
TEXTText
BLOBBLOB
REALFloat
FLOAFloat
DOUBFloat

Note that the type string FLOATING POINT will be interpreted as an integer, and not a real, since the first substring listed will match the INT at the end of the name. This first entry takes precedence over subsequent substrings, resulting in an unexpected cast. It is best to use somewhat standard database types to ensure correct conversion.

Once a specific datatype has been determined, the actual conversion is done using the standard rules. See Table 7-1 for specifics.

See Also

CREATE TABLE [SQL Cmd, Ap C]

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.