Numeric Types
Synopsis
YSQL support integers, floating-point numbers, and fixed-point numbers of different value ranges and precisions.
Data type | Description | Min | Max |
---|---|---|---|
BIGINT | 8 bytes | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
DEC | Exact 64-bit fixed point number | variable | variable |
DECIMAL | Exact 64-bit fixed point number | variable | variable |
DOUBLE PRECISION | Inexact 64-bit floating point number | 15-digit precision | 15-digit precision |
FLOAT | Inexact 64-bit floating point number | variable | variable |
INTEGER | 4-byte integer | -2,147,483,648 | 2,147,483,647 |
INT | 4-byte interger | -2,147,483,648 | 2,147,483,647 |
NUMERIC | Exact 64-bit fixed point number | variable | variable |
REAL | Inexact 32-bit floating point number | 6-digit precision | 6-digit precision |
SMALLINT | 2-byte integer | -32,768 | 32,767 |
Integers
The following keywords are used to specify a column of type integer for different constraints, including its value ranges.
type_specification ::= SMALLINT | INT | INTEGER | BIGINT
integer_literal ::= [ + | - ] digit [ { digit | , } ... ]
- Columns of type
SMALLINT
,INT
,INTEGER
, orBIGINT
can be part of thePRIMARY KEY
. - Values of different integer data types are comparable and convertible to one another.
- Values of integer data types are convertible but not comparable to floating point number.
- Currently, values of floating point data types are not convertible to integers. This restriction will be removed in the near future.
Floating-point numbers
The following keywords are used to specify a column of floating-point types for different constraints including its value ranges.
type_specification ::= { FLOAT | DOUBLE PRECISION | REAL }
floating_point_literal ::= non_integer_fixed_point_literal | "NaN" | "Infinity" | "-Infinity"
- Columns of type
REAL
,DOUBLE PRECISION
, andFLOAT
can be part of thePRIMARY KEY
. - Values of different floating-point and fixed-point data types are comparable and convertible to one another.
- Conversion from floating-point types into
DECIMAL
will raise an error for the special valuesNaN
,Infinity
, and-Infinity
. - The ordering for special floating-point values is defined as (in ascending order):
-Infinity
, all negative values in order, all positive values in order,Infinity
, andNaN
. - Values of non-integer numeric data types are neither comparable nor convertible to integer although integers are convertible to them. This restriction will be removed.
Fixed-point numbers
The following keywords are used to specify a column of floating-point types for different constraints including its value ranges.
type_specification ::= { DEC | DECIMAL | NUMERIC }
fixed_point_literal ::= [ + | - ] { digit [ digit ...] '.' [ digit ...] | '.' digit [ digit ...] }
- Columns of type
DEC
,DECIMAL
, andNUMERIC
can be part of thePRIMARY KEY
. - Values of different floating-point and fixed-point data types are comparable and convertible to one another.
- Values of non-integer numeric data types are neither comparable nor convertible to integer although integers are convertible to them. This restriction will be removed.
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .