REAL

In SQL, the REAL data type is used to represent floating-point numbers. It is a numeric data type that can store values with decimal points and can have a precision of up to 7 digits.

The SQL REAL data type is commonly used for storing data that requires high precision and accuracy, such as financial data, scientific measurements, and GPS coordinates. It is similar to the FLOAT data type, but has a smaller storage size and lower precision.

Syntax

When defining a REAL column in a table, you can specify the precision and scale of the data type using the following syntax:

column_name REAL(precision, scale)

where precision is the total number of digits that can be stored, including digits to the left and right of the decimal point, and scale is the number of digits to the right of the decimal point.

Example

For example, to define a REAL column called price, you would use the following SQL statement:

CREATE TABLE products (
  id INTEGER PRIMARY KEY,
  name TEXT,
  price REAL
);

In this example, the price column can store values with up to 8 digits to the left of the decimal point and 2 digits to the right, such as 12345.67 or -9876.54.

To insert data into a REAL column, you can use a standard INSERT statement:

INSERT INTO products (id, name, price)
VALUES (1, 'Product A', 19.99);

You can also perform arithmetic and comparison operations on REAL values using standard SQL syntax:

SELECT price * 2.0 
FROM products;

SELECT * 
FROM products 
WHERE price > 50.0;

In summary, the SQL REAL data type is a numeric data type used to store floating-point numbers with high precision and accuracy. It is commonly used for financial data, scientific measurements, and GPS coordinates. When defining a REAL column, you can specify the precision and scale of the data type.