In SQLite, the REAL data type is used to store floating-point values. It is one of the five main data types supported by SQLite, alongside INTEGER, TEXT, BLOB, and NULL.
REAL data type is commonly used to represent decimal numbers, such as prices, measurements, or percentages. SQLite uses an 8-byte IEEE floating-point number to store REAL values, which provides a high level of precision and allows for a wide range of values to be stored.
One thing to note about the REAL data type in SQLite is that it is not as precise as other data types, such as
NUMERIC, which can lead to rounding errors in certain situations. Additionally, REAL values are stored in binary format, which can make them difficult to read and compare directly.
When defining a column in SQLite, the REAL data type can be specified using the keyword
REAL. For example, to
create a table with a column named “price” of type REAL, the following SQL statement can be used:
CREATE TABLE products ( id INTEGER PRIMARY KEY, name TEXT, price REAL );
Once a column is defined as REAL, it can be populated with values using
SQL INSERT statements, such as:
INSERT INTO products (name, price) VALUES ('Widget A', 12.99); INSERT INTO products (name, price) VALUES ('Widget B', 24.95);
REAL data type in SQLite is a versatile and useful way to store floating-point values with a high level of precision. However, it is important to be aware of its limitations and potential for rounding errors when working with large or precise numbers.