Numeric types¶
GQL supports integers, floating-point numbers, and arbitrary-precision numbers. Integers can be signed or unsigned, while floating-point numbers and arbitrary-precision numbers are always signed.
Signed numbers can be positive, negative, or zero, and are by default positive if no sign is specified. Unsigned numbers are always non-negative.
Signed integers¶
A signed integer is either non-negative (positive or zero) or negative.
The following table lists the signed integer types and their value ranges.
| Type | Declared keywords | Range |
|---|---|---|
| INT64 | INT and INT64 |
-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 |
| INT32 | INT32 |
-2,147,483,648 ~ 2,147,483,647 |
| INT16 | INT16 |
-32,768 ~ 32,767 |
| INT8 | INT8 |
-128 ~ 127 |
Unsigned integers¶
An unsigned integer is always non-negative.
The following table lists the unsigned integer types and their value ranges.
| Type | Declared keywords | Range |
|---|---|---|
| UINT64 | UINT and UINT64 |
0 ~ 18,446,744,073,709,551,615 |
| UINT32 | UINT32 |
0 ~ 4,294,967,295 |
| UINT16 | UINT16 |
0 ~ 65,535 |
| UINT8 | UINT8 |
0 ~ 255 |
Floating-point numbers¶
Both single-precision floating-point format (FLOAT) and double-precision floating-point format (DOUBLE) are supported.
| Type | Declared keywords | Range |
|---|---|---|
| FLOAT32 | FLOAT32, FLOAT |
3.4E +/- 38 |
| FLOAT64 | FLOAT64, DOUBLE |
1.7E +/- 308 |
Scientific notation is also supported, such as 1e2, 1.1e2, .3e4, 1.e4, and -1234E-10.
Special values¶
FLOAT (FLOAT32) and DOUBLE (FLOAT64) types support the following special values:
| Expression | Description | Type |
|---|---|---|
1.0f/0.0, 1.0d/0.0 |
Positive infinity | FLOAT / DOUBLE |
-1.0f/0.0, -1.0d/0.0 |
Negative infinity | FLOAT / DOUBLE |
0.0f/0.0, 0.0d/0.0 |
Not a number | FLOAT / DOUBLE |
Note
The f and d indicate types FLOAT (FLOAT32) and DOUBLE (FLOAT64) respectively.
These special values can also be created by casting from strings. For more information, see Conversions of special values.
Arbitrary-precision numbers¶
Arbitrary-precision numbers are used to store a large number of digits where exactness is required.
Syntax¶
- arbitrary_precision_number
arbitrary_precision_number ::=
( 'DECIMAL' | 'DEC' ) (precision (',' scale)? )?
The precision is the total count of digits in the whole number and has a range of 1 to 256.
The scale is the count of digits to the right of the decimal point and has a range of 0 to 128. The scale must be no larger than the precision.
Default values¶
If neither the precision nor the scale is specified, the precision defaults to 10 and the scale defaults to 0.
If only the precision is specified, the scale defaults to 0.
Rules¶
If the declared precision and scale are the same, only decimals whose absolute values are less than 1 can be stored. For example, DECIMAL(3, 3) can only store values in the range of -0.999 to 0.999.
If the count of digits to the left of the decimal point is greater than the difference between the declared precision and scale, an error is returned. For example, if the declared precision is 4 and the declared scale is 2, the value 123.4 cannot be stored.
If the count of digits to the right of the decimal point is greater than the declared scale, the value is rounded to the declared scale. For example, if the declared precision is 4 and the declared scale is 2, the value 1.234 is stored as 1.23.
If the count of digits to the right of the decimal point is smaller than the declared scale, zeros are padded to the right of the value to match the declared scale. For example, if the declared precision is 4 and the declared scale is 2, the value 12.3 is displayed as 12.30.
Declaration examples¶
Example 1:
'''
CREATE GRAPH TYPE IF NOT EXISTS person AS
{ NODE Person
( {
id INT64 PRIMARY KEY,
salary DECIMAL(10, 4) DEFAULT 10000.00M,
is_adult BOOL DEFAULT TRUE,
name STRING DEFAULT 'John Doe',
hobbies LIST<STRING> DEFAULT ['reading', 'swimming'],
birthday DATE DEFAULT DATE('1990-01-01')
} )
}
'''
In the preceding example, the property id is of the integer type (INT64) and the property salary is of the arbitrary-precision type (DECIMAL(10, 4)).
Example 2:
'''
CREATE GRAPH TYPE IF NOT EXISTS person2 AS
{ NODE Person
( {
id INT64 PRIMARY KEY,
salary DECIMAL
} )
}
'''
In the preceding example, the property salary is of the arbitrary-precision type (DECIMAL) with the default precision and scale of 10 and 0, respectively.