How to use REAL Storage Class In SQL
We can store those values with the REAL storage class. REAL storage class is used to store floating point numbers. SQLite uses 8 bytes (64 bits) to store floating–point numbers. Therefore, we can store both types i.e. single precision and double precision value.
In this, we will see how we can store double and float values in our table in SQLite. We will first create a table namely ‘w3wiki‘ with (id, name, contest_score, and total_score ) as columns.
Query:
--table creation
CREATE TABLE w3wiki (
id INTEGER,
name TEXT,
contest_score REAL,
total_score REAL
);
Explanation: We have created a table ‘w3wiki’ and set contest_score and total_score as REAL. In those columns, we are going to store float and double values. After executing the above command, we can clearly see a table has been created in our database.
As we have done with creating a table, now lets insert some values and display it.
Query:
--Inserting values in our table
INSERT INTO w3wiki(id, name, contest_score ,total_score)
VALUES(01,'Vishu', 22.5 , 505.623523);
INSERT INTO w3wiki(id, name, contest_score ,total_score)
VALUES(02,'Neeraj', 20.5 , 501.2237562);
INSERT INTO w3wiki(id, name, contest_score ,total_score)
VALUES(03,'Aayush', 22.3 , 495.3534532);
INSERT INTO w3wiki(id, name, contest_score ,total_score)
VALUES(04,'Vivek', 18.2 , 491.10545610123);
--displaying values of our table
SELECT * FROM w3wiki;
Output:
Explanation: In the above image, we can clearly observe that float and double values are inserted in contest_score and toal_score columns. We can clearly see that both the columns are created with REAL storage class. Therefore, it can accommodate both values without losing any precision.
How to Insert Double and Float Values in SQLite?
SQLite, a lightweight and server–less relational database management system, provides powerful features for handling various data types, including double and float values.
In this article, we will explore various methods along with examples for inserting double and float values into SQLite tables, ensuring data integrity and precision.