NUMERIC Data Type

NUMERIC is a synonym for the   DECIMAL data type and behaves the same way. The documentation below is a mirror of the documentation for the DECIMAL data type.

NUMERIC provides an exact numeric in which the precision and scale can be arbitrarily sized. You can specify the precision (the total number of digits, both to the left and the right of the decimal point) and the scale (the number of digits of the fractional component). The amount of storage required depends on the precision you specify.

Syntax

NUMERIC [(precision [, scale ])]

precision

Must be between 1 and 38. If not specified, the default precision is 5.

Prior to version 2.8 of Splice Machine, precision was limited to 31. If you’re using an earlier version of either Splice Machine, the Splice Machine JDBC driver, or the Splice Machine sqlshell.sh command line interpreter, precision is limited to 31.

scale

Must be less than or equal to the precision. If not specified, the default scale is 0.

Usage Notes

Here are several notes about using the NUMERIC data type:

  • An attempt to put a numeric value into a NUMERIC is allowed as long as any non-fractional precision is not lost. When truncating trailing digits from a NUMERIC value, Splice Machine rounds down. For example:
      -- this cast loses only fractional precision
    values cast (1.798765 AS numeric(5,2));
    1
    --------
    1.79
    	-- this cast does not fit:
    values cast (1798765 AS numeric(5,2));
    ERROR 22003: The resulting value is outside the range for the data type DECIMAL/NUMERIC(5,2).
    
  • When mixed with other data types in expressions, the resulting data type follows the rules shown in Storing values of one numeric data type in columns of another numeric data type.
  • When two numeric values are mixed in an expression, the scale and precision of the resulting value follow the rules shown in Scale for decimal arithmetic.
  • Integer constants too big for BIGINT are made NUMERIC constants.

Corresponding Compile-time Java Type

java.math.BigDecimal

JDBC Metadata Type (java.sql.Types)

NUMERIC

Examples

VALUES 123.456;
VALUES 0.001;