website logo
⌘K
🏠Homepage
👋Introduction
Key Concepts & Architecture
🚀Getting Started
👨‍💻SQL Reference
SQL Queries
SQL Clauses
SQL Data Types
SQL Functions
Schema
🚨Error Handling
🆚Differences Between Oxla vs. PostgreSQL
Docs powered by archbee 

Numeric Type

23min

By the end of this section, you will learn about the NUMERIC data type that Oxla supports - the integer type (Integer & Long) and the floating point type (Float & Double).

Integer Type

The INTEGER data type is whole numbers, and they do not have decimal numbers. It is 32-bit signed and has a limit from -32,768 to 32,768.

Format

Format
|
column_name int


Example

The following is an example of how to create a column using an INTEGER type:

Create a table
|
CREATE TABLE cities (
    city_id int,
    cityname string,
    population int
);

INSERT INTO cities (city_id, cityname, population)
VALUES
    (8557411, 'New York', 8419000),
    (8557421, 'London', 8982000),
    (8557451, 'Hongkong', 7482000),
    (8557491, 'Seoul', 9776000);


Now, run the following query to display the table:

Display the table
|
SELECT * FROM cities;


You will get the following table as the output:

Output
|
+----------+-----------+------------+
| city_id  | cityname  | population |
+----------+-----------+------------+
| 8557411  | New York  | 8419000    |
| 8557421  | London    | 8982000    |
| 8557451  | Hongkong  | 7482000    |
| 8557491  | Seoul     | 9776000    |
+----------+-----------+------------+


Long Type

The LONG data type is similar to Integer but is designed to store numbers exceeding the INTEGER range limit. This is 64-bit signed and has a limit from -2,147,483,648 to 2,147,483,648.

Format

Format
|
column_name LONG


Example

The following is an example of how to create a column using a LONG type:

Create a table
|
CREATE TABLE galaxies (
    galaxy_name string,
    star LONG
);

INSERT INTO galaxies (galaxy_name, star)
VALUES
    ('Milky Way', 100000000000),
    ('Cigar', 30000000000),
    ('Andromeda', 1000000000000),
    ('Cosmos', 2000000000000000000);


Now, run the following query to display the table:

Display the table
|
SELECT * FROM galaxies;


You will get the galaxies' names and their stars as the final output:

Output
|
+---------------+---------------------+
| galaxy_name   | star                |
+---------------+---------------------+
| Milky Way     | 100000000000        |
| Cigar         | 30000000000         |
| Andromeda     | 1000000000000       |
| Cosmos        | 2000000000000000000 |
+---------------+---------------------+


Float Type

The FLOAT data type is a 32-bit floating-point number with n precision.

Format

Format
|
column_name FLOAT


Example

1) Create a table

Here we are creating a numbers table named with a FLOAT type:

Create a table
|
CREATE TABLE numbers (
    column_1 FLOAT
);

INSERT into numbers (column_1)
VALUES (1.234568);


The following is the table showing that the column can contain at least six decimal digits:

Output
|
+------------+
| column_1   |
+------------+
| 1.234568   |
+------------+


2) Rounding

Rounding might happen if the precision of an input number is too high.

Create a table
|
CREATE TABLE numbers (
    column_1 FLOAT
);

INSERT into numbers (column_1)
VALUES (1.2345689);


Here is the rounding result from the above command:

Output
|
+------------+
| column_1   |
+------------+
| 1.234569   |
+------------+


3) Create a table with numbers exceeding the range

FLOAT type only stores 32-bit floating-point numbers. In this example, we input the numbers that exceed the range:

Create a table
|
CREATE TABLE numbers (
    column_1 FLOAT
);

INSERT into numbers1x (column_1)
VALUES (1.2345682991822);


The final output will only return numbers that match the range:

Output
|
+------------+
| column_1   |
+------------+
| 1.2345684  |
+------------+


Double Type

The DOUBLE data type is a 64-bit floating-point number with n precision.

Format

Format
|
column_name DOUBLE


Example

1) Create a table

Here we are creating a numbersdouble table named with a DOUBLE type.

Create a table
|
CREATE TABLE numbersdouble (
    column_1 DOUBLE
);

INSERT into numbersdouble (column_1)
VALUES (1.234568817283122);


The following is the table showing that the column can contain at least fifteen decimal digits:

Output
|
+--------------------+
| column_1           |
+--------------------+
| 1.234568817283122  |
+--------------------+


2) Rounding

Rounding might happen if the precision of an input number is too high.

Create a table
|
CREATE TABLE numbersdouble (
    column_1 DOUBLE
);

INSERT into numbersdouble (column_1)
VALUES (1.234568817283122773);


Here is the rounding result from the above command:

Output
|
+---------------------+
| column_1            |
+---------------------+
| 1.2345688172831228  |
+---------------------+




Updated 11 May 2023
Did this page help you?
Yes
No
PREVIOUS
String Type
NEXT
JSON Type
Docs powered by archbee 
TABLE OF CONTENTS
Integer Type
Format
Example
Long Type
Format
Example
Float Type
Format
Example
Double Type
Format
Example

Dedicated to data analytics that provides 10x faster execution of analytical queries than current state of the art solutions. We are launching SOON! Join the waiting list for more info.




©2022 Oxla