Updated on 2024-12-31 GMT+08:00

Fixed Precision

Name

Description

Storage Space

Value Range

Literal

DECIMAL

Decimal number with fixed precision. The precision can be as high as 38 bits, but for optimal performance, a precision of less than 18 bits is recommended.

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)    

--Drop a table.
DROP TABLE decimal_t1;  

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

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


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