DECFLOAT type
Applies to: Databricks SQL
Databricks Runtime 19 and above
Represents base-10 floating-point numbers with 16 or 34 significant digits and no fixed scale.
Syntax
DECFLOAT [ ( p ) ]
p: The maximum number of significant decimal digits. Supported values are 16 and 34. The default is 34.
DECFLOAT does not accept a scale argument. Each value has its own exponent.
Limits
Property |
|
|
|---|---|---|
Significant digits | Up to 16 | Up to 34 |
Smallest positive nonzero value |
|
|
Largest positive finite value |
|
|
The same limits apply to negative numbers. Both types also support infinity and NaN.
Literals
Use CAST with a string or supported numeric value. Strings can also contain NaN, Inf, or Infinity.
Notes
DECFLOAT represents decimal values such as 0.1 exactly. Values that exceed the precision can round without an error, including with TRY_CAST. Cast decimal text directly. Converting through FLOAT or DOUBLE can lose precision.
String output preserves trailing zeros, so equal values such as 1.5 and 1.50 can produce different strings (+15E-1 and +150E-2). Casts from DECFLOAT to DECIMAL round half up, independently of DECFLOAT_ROUNDING_MODE.
- Arithmetic preserves precision when both operands have the same DECFLOAT type. Mixed precisions or operations with other supported numeric types use
DECFLOAT(34). SUMandAVGreturnDECFLOAT(34).MINandMAXpreserve the input precision.SQRT,ABS, andROUNDaccept DECFLOAT directly.
DECFLOAT_ROUNDING_MODE controls rounding for casts to DECFLOAT, +, -, *, /, SQRT, SUM, and AVG. The default is ROUND_HALF_EVEN. Other supported modes are ROUND_HALF_UP, ROUND_CEILING, ROUND_FLOOR, and ROUND_DOWN. DIV removes the fractional part of the result, regardless of DECFLOAT_ROUNDING_MODE. ROUND, BROUND, and TRUNCATE use their own rounding rules.
> SET DECFLOAT_ROUNDING_MODE = ROUND_FLOOR;
> SELECT CURRENT_DECFLOAT_ROUNDING_MODE();
ROUND_FLOOR
With the default rounding mode, overflow produces infinity and division by zero produces infinity or NaN. ANSI mode does not change these results. Supported TRY_* arithmetic functions preserve infinity and NaN rather than returning NULL. NaNs compare equal and sort after positive infinity. Positive and negative zero compare equal. Use ISNAN to detect NaN.
Examples
> SELECT CAST('1.5' AS DECFLOAT(34)) + CAST('2.5' AS DECFLOAT(34)) AS total;
+40E-1
> SELECT CAST(CAST('1.23E+100' AS DECFLOAT(34)) AS STRING);
+123E+98
> SELECT typeof(CAST('1' AS DECFLOAT(16)) + 1);
decfloat(34)
Limitations
- Remainder and bitwise operations are unsupported.
- Functions that require
DOUBLEinputs do not accept DECFLOAT directly. Convert the value toDOUBLEfirst (this can result in precision loss). - DECFLOAT is not compatible with deletion vectors. When creating a Delta table with DECFLOAT columns, set
TBLPROPERTIES ('delta.enableDeletionVectors' = 'false'). For existing tables, drop the deletion-vector table feature before adding DECFLOAT columns. - Delta tables containing DECFLOAT cannot have Iceberg reads enabled.
- Writing DECFLOAT values directly to Parquet files is unsupported.
- DECFLOAT columns have no min/max statistics for data skipping. They cannot be partition columns, clustering keys, Z-order columns, or Bloom filter index columns.
- Changing a column between
DECFLOAT(16)andDECFLOAT(34)withALTER COLUMNis unsupported.