SQL Data Types
Hazelcast supports a subset of SQL data types. Each data type is mapped to a Java class, which represents the type’s value in Hazelcast.
Type Name | Supported Casting Types | Java Class |
---|---|---|
|
|
|
|
All types |
|
|
|
|
|
|
|
|
N/A |
Custom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
All types |
Any Java class |
Casting and Data Type Conversion
To convert one data type to another (also known as casting), you can use the CAST(expression AS type_name)
function.
Numeric Literals
When numeric literals are assigned SQL types:
-
Integers, e.g., 1 and 42, receive the narrowest possible among
TINYINT
,SMALLINT
,INTEGER
,BIGINT
andDECIMAL
. -
Floating-point numbers, e.g., 1.2 and 4.2, receive
DECIMAL
. -
Scientific notation (exponential form), e.g., 1e1 or 4.2e2, receives
DOUBLE
.
As you realized, integers are optimized for storage, whereas floating-point numbers are not subject to such optimization. This is because REAL
and DOUBLE
cannot exactly represent all decimal numbers (see IEEE 754), and exactness cannot be compromised for financial applications. Finally, because of its rare usage, scientific notation is not optimized for storage, i.e., not tried to narrow to REAL
.
Numbers that are represented in scientific notation and out of range for DOUBLE
will cause overflow and be interpreted as ∞ or -∞. For example, 1.8e+308 is greater than the largest possible finite value of DOUBLE
, which is 1.7976931348623157e+308, and so it is only valid in the form 18000…0.