Updated on 2024-05-29 GMT+08:00

Fixed Precision

Name

Description

Storage Space

Value Range

Literal

DECIMAL

Decimal number with fixed precision. The maximum precision is 38 bits, but the precision with less than 18 bits can ensure the best performance.

Decimal has two input parameters:

  • precision: total number of digits. The default value is 38.
  • scale: number of decimal places. The default value is 0.
    NOTE:

    If scale is 0 and precision is 38, the maximum precision is 19 bits.

64 bits

DECIMAL

NUMERIC

Same as DECIMAL

128 characters

NUMERIC

Table 1 Examples of literals

Literal

Data Type

DECIMAL '0'

DECIMAL(1)

DECIMAL '12345'

DECIMAL(5)

DECIMAL '0000012345.1234500000'

DECIMAL(20, 10)

--Create a table containing DECIMAL data.
CREATE TABLE decimal_t1 (dec_col1 DECIMAL(10,3)) ;    

– Insert data of the DECIMAL type.
insert into decimal_t1 values (DECIMAL '5.325');     

--View data.
SELECT * FROM decimal_t1;  
 dec_col1  
---------   
 5.325 
(1 row)    

-- Negative example: The number of decimal places exceeds the defined length. As a result, the SQL statement fails to be executed.
insert into decimal_t1 values (DECIMAL '5.3253');
Query 20201126_034601_00053_tq98i@default@HetuEngine failed: Insert query has mismatched column types: Table: [decimal(10,3)], Query: [decimal(5,4)]

--Drop a table.
DROP TABLE decimal_t1;  

--Create a NUMERIC type table.
CREATE TABLE tb_numberic_hetu(col1 NUMERIC(9,7));
CREATE TABLE

--Insert data.
INSERT INTO tb_numberic_hetu values(9.12);
INSERT: 1 row

--View data.
SELECT * FROM tb_numberic_hetu;
col1    
------------
  9.1200000 
(1 row)