Get startedGet started for free

Numeric data types

1. Numeric data types

Thanks for hopping back in! We've already hit on text data types; now, it's time to explore numeric data.

2. Numeric data types

Numeric data can come in all shapes and sizes like integers, dollar amounts, decimals, negative values, ID's, and even numeric constants. To store numeric data like this, Snowflake uses the `NUMBER` data type. `NUMBER` allows us to control the size of numeric values; more on this in a bit. In Snowflake, there are additional data types synonymous with `NUMBER`, like `DECIMAL` and `INTEGER. We'll stick with `NUMBER`!

3. Precision and scale

When defining a numeric column, there are two values that can be passed to `NUMBER` to control its size; precision and scale. Precision is the total number of digits the number can store. Here, we've specified a precision of 4. This means that any values in this column could have up to total 4 digits. Scale is the number of digits to the right of the decimal point. 1.75 could fit in this column, as it has 3 total digits and 2 to the right of the decimal point. However, 624.99 cannot; it has 5 total digits.

4. Precision and scale

Sometimes, this logic can be tricky. Defining a column using `NUMBER(3, 0)` allows us to store 42, but not 1000 or 41.99 since each has 4 digits. Weird, since 41.99 is technically smaller than 42. Precision and scale are not required to create a numeric column. If you don't provide these values, the default will be `NUMBER(38, 0)`.

5. Defining numeric data types

Here, we can choose to provide a precision and scale or not. For the `price` column, we only want dollar amounts` up to $999.99. Using precision and scale, we can enforce this. To ensure that `quantity` is only integer values, we set a scale of zero. The type for each column shows both its precision and scale. Since precision and scale were not specified for `id`, its type is `NUMBER(38, 0)`.

6. FLOAT data type

There's another important type of numeric data; floats. The `FLOAT` data type is most commonly used in scientific and statistical calculations, and is considered an "approximate" numeric type, since it has the possibility of rounding errors. Why might someone use `FLOAT`? Well, it's quite fast, and can handle extreme scale. `FLOAT` values can be defined using the `FLOAT` keyword. When running a `DESCRIBE TABLE`, the results will look different than when using `NUMBER`. Check it out!

7. Manipulating numeric data

Numeric data types can be used and manipulated in a number of different ways. We can compare values, perform arithmetic operations, aggregate data, and calculate summary statistics to help extract value from numeric data in Snowflake. We'll explore some of these operations later in the course!

8. Let's practice!

For now, it's your turn practice - good luck!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.