Snowflake 3
Snowflake 3
NUMBER
Numbers up to 38 digits, with an optional precision and scale:
Precision Total number of digits allowed.
Scale Number of digits allowed to the right of the decimal point.
By default, precision is 38 and scale is 0 (i.e. NUMBER(38, 0) ). Note that precision
limits the range of values that can be inserted into (or cast to) columns of a given type.
For example, the value 999 fits into NUMBER(38,0) but not into NUMBER(2,0) .
The maximum scale (number of digits to the right of the decimal point) is 37. Numbers
that have fewer than 38 significant digits, but whose least significant digit is past the
37th decimal place, for example
0.0000000000000000000000000000000000000012 (1.2e-39), cannot be
represented without losing some digits of precision.
Note
If data is converted to another data type with lower precision, then back to the
higher-precision form, the data can lose precision. For example, you lose
precision if you convert a NUMBER(38,37) value to DOUBLE (which has a
precision of approximately 15 decimal digits), and then back to NUMBER.
Snowflake also supports the FLOAT data type, which allows a wider range of values,
although with less precision.
+---------+--------------+--------+-------+---------+-------------+-----
| name | type | kind | null? | default | primary key | uniq
|---------+--------------+--------+-------+---------+-------------+-----
| NUM | NUMBER(38,0) | COLUMN | Y | NULL | N | N
| NUM10 | NUMBER(10,1) | COLUMN | Y | NULL | N | N
| DEC | NUMBER(20,2) | COLUMN | Y | NULL | N | N
| NUMERIC | NUMBER(30,3) | COLUMN | Y | NULL | N | N
| INT | NUMBER(38,0) | COLUMN | Y | NULL | N | N
| INTEGER | NUMBER(38,0) | COLUMN | Y | NULL | N | N
+---------+--------------+--------+-------+---------+-------------+-----
Precision
Snowflake uses double-precision (64 bit) IEEE 754 floating-point numbers.
Precision is approximately 15 digits. For example, for integers, the range is from
-9007199254740991 to +9007199254740991 (-253 + 1 to +253 - 1). Floating-point
values can range from approximately 10-308 to 10+308. (More extreme values between
approximately 10-324 and 10-308 can be represented with less precision.) For more
details, see the Wikipedia article on double-precision numbers.
Snowflake supports the fixed-point data type NUMBER, which allows greater
precision, although a smaller range of exponents.
Special values
Snowflake supports the following special values for FLOAT:
'NaN' (Not A Number).
'inf' (infinity).
'-inf' (negative infinity).
The symbols 'NaN' , 'inf' , and '-inf' must be in single quotes, and are case-
insensitive.
Comparison semantics for 'NaN' differ from the IEEE 754 standard in the following
ways:
Rounding errors
Floating point operations can have small rounding errors in the least significant
digit(s). Rounding errors can occur in any type of floating-point processing, including
trigonometric functions, statistical, and geospatial functions.
Errors can vary each time the query is executed.
Errors can be larger when operands have different precision or scale.
Errors can accumulate, especially when aggregate functions (e.g. SUM() or AVG())
process large numbers of rows. Casting to a fixed-point data type before aggregating
can reduce or eliminate these errors.
Rounding errors can occur not only when working with SQL, but also when working
with other code (e.g. Java, JavaScript, or Python) that runs inside Snowflake (e.g. in
UDFs and stored procedures).
When comparing two floating-point numbers, Snowflake recommends comparing for
approximate equality rather than exact equality.
+---------+--------------+--------+-------+---------+-------------+-----
| name | type | kind | null? | default | primary key | uniq
|---------+--------------+--------+-------+---------+-------------+-----
| D | FLOAT | COLUMN | Y | NULL | N | N
| F | FLOAT | COLUMN | Y | NULL | N | N
| DP | FLOAT | COLUMN | Y | NULL | N | N
| R | FLOAT | COLUMN | Y | NULL | N | N
+---------+--------------+--------+-------+---------+-------------+-----
Note
The DESCRIBE TABLE command’s “type” column displays the data type “FLOAT”
not only for FLOAT, but also for synonyms of FLOAT (e.g. DOUBLE, DOUBLE
PRECISION, and REAL).
Numeric constants
Constants (also known as literals) refers to fixed data values. The following formats
are supported for numeric constants:
[+-][digits][.digits][e[+-]digits]
Where:
+ or - indicates a positive or negative value. The default is positive.
digits is one or more digits from 0 to 9.
e (or E ) indicates an exponent in scientific notation. At least one digit must follow
the exponent marker if present.
The following numbers are all examples of supported numeric constants:
15
+1.34
0.2
15e-03
1.234E2
1.234E+2
-1