Top 7 Snowflake Data Types

Numeric, Text, Date and Time, Boolean, Semi-Structured, Binary, Spatial

Top 7 Snowflake Data Types

Snowflake is a cloud-based data warehouse service, and like many relational databases, it offers a variety of data types to represent different kinds of information. Here are the major data types available in Snowflake:

Numeric Types

Sample code that will create a table with each example of numeric data types below

Before delving into the various numeric data types, it's crucial to grasp the concepts of precision and scale:

Precision refers to the total count of digits that a number can have, encompassing both those before and after the decimal point.

Scale, on the other hand, denotes the number of permissible digits following the decimal point.

It's important to note that converting data to a type with a reduced precision and then reverting it back to its original precision can result in a loss of data accuracy.

While precision itself doesn't dictate storage needs (for instance, numbers in columns defined as NUMBER(5,0) and NUMBER(25,0) will consume equivalent storage), the scale indeed affects storage. For example, a value in a column defined as NUMBER(20,5) will occupy more storage than one in NUMBER(20,0) due to the additional decimal precision. Furthermore, higher scale values may slightly increase processing time and memory usage.

  1. NUMBER: A number with optional precision and scale.
  2. INTEGER, INT: A 38-digit maximum integer.
  3. FLOAT, FLOAT4, FLOAT8: Floating-point numbers.
  4. DECIMAL, NUMERIC: Fixed-point numbers with user-defined precision.

Text Types

Sample code that will create a table with each example of text Snowflake data types below

Before diving into the various text data types, it's essential to understand the distinction between fixed-length and variable-length strings:

Fixed-Length – This means that the string will always occupy space for the maximum length specified, even if the actual data stored is shorter. For instance, a CHAR(5) column will always use space for 5 characters, regardless of the actual string length.

Variable-Length – This means that the string will occupy space based on the actual length of the data stored. For example, a VARCHAR(50) column that contains the word "Snowflake" will only use space for 9 characters.

Note: Storing shorter strings in fixed-length columns can result in wasted storage space. Conversely, variable-length strings offer more storage efficiency but might require a bit more processing overhead to handle the variability in length.

  1. STRING, VARCHAR, CHAR: Variable-length character string.
  2. TEXT: Alias for STRING.
  3. BINARY: Binary data.

Date and Time Types

Sample code that will create a table with each example of Data & Time Snowflake Data Types below

In the context of Snowflake and many other databases that deal with timestamps and time zones, "NTZ" and "LTZ" are abbreviations related to time zone handling:

NTZ (No Time Zone):

  1. Stands for "No Time Zone" or "Without Time Zone."
  2. TIMESTAMP_NTZ data type represents date and time without any time zone adjustment or information.
  3. When you store a timestamp in this type, Snowflake doesn’t associate it with any specific time zone.
  4. If you insert '2021-09-12 14:00:00' into a TIMESTAMP_NTZ column, it just stores it as '2021-09-12 14:00:00' without any reference to a time zone.

LTZ (Local Time Zone):

  1. Stands for "Local Time Zone" or "With Local Time Zone."
  2. TIMESTAMP_LTZ data type automatically adjusts to the time zone of the client that retrieves it.
  3. When storing a timestamp, Snowflake normalizes the data to Coordinated Universal Time (UTC). When retrieving the timestamp, it adjusts the time based on the time zone of the client.
  4. For example, if you're in the UTC+2 time zone and insert '2021-09-12 14:00:00' into a TIMESTAMP_LTZ column, Snowflake might store it internally as '2021-09-12 12:00:00' (normalized to UTC). When you retrieve it, Snowflake will adjust it back to '2021-09-12 14:00:00' for your time zone.

Time Zone – Some TIMESTAMP data types in Snowflake can adjust for the client's time zone, either by storing an offset or adjusting the time based on the client's settings.

Understanding the difference between these timestamp types is crucial when working with global data and systems that span multiple time zones. It helps ensure that date and time values are accurately represented and interpreted, regardless of where or when they are accessed.

Precision – Refers to the granularity of the timestamp, specifically how many fractions of a second are stored. For instance, TIMESTAMP(3) can store milliseconds, while TIMESTAMP(6) can store microseconds.

Note: When working with date and time types, always be aware of time zone implications to avoid data inconsistencies or misinterpretations. Precision can also impact storage slightly, with higher precision values consuming marginally more space.

  1. DATE: Represents a date (year, month, day).
  2. TIME: Represents a time (hour, minute, second, fraction).
  3. TIMESTAMP: Represents a date and time.
  4. TIMESTAMP_LTZ (TIMESTAMP WITH LOCAL TIME ZONE): Adjusts for the time zone of the client.
  5. TIMESTAMP_NTZ (TIMESTAMP WITHOUT TIME ZONE): No time zone adjustment.
  6. TIMESTAMP_TZ (TIMESTAMP WITH TIME ZONE): Stores a time zone offset.

Boolean Type

Example of Boolean Snowflake Data Types
  1. BOOLEAN: TRUE or FALSE values.

Semi-Structured Types

Example of Semi-Structured Snowflake Data Types

Before exploring the semi-structured data types, it's pivotal to understand their flexibility and storage implications:

Flexibility – Semi-structured data types like VARIANT, OBJECT, and ARRAY can store a mix of simple and complex data, including nested structures, without a predefined schema.

Storage – While these types provide immense flexibility, they often consume more storage than traditional relational columns due to the overhead of storing complex structures.

Note: While semi-structured data types offer the advantage of storing varied data without a fixed schema, it's essential to be mindful of the processing overhead and storage implications. Efficient querying on such data might require specific functions and strategies to parse and interpret the nested structures.

  1. VARIANT: Can store values of any other data type, including objects (like JSON) or arrays.
  2. OBJECT: Similar to VARIANT but optimized for objects.
  3. ARRAY: An ordered collection of one or more values, which can be of any data type.

Binary Data Types

Example of Binary Snowflake Data Types
  1. BYTE: Binary data.

Spatial Data Type

Example of Spatial Snowflake Data Types
  1. GEOGRAPHY: Used for storing spatial data.

Remember that the best practice when designing a table in Snowflake (or any database) is to choose the most appropriate data type for each column based on the nature of the data it will store. This ensures optimal storage and performance.

New Release
Share

Get in Touch to Learn More

See Why Users Love CastorDoc
Fantastic tool for data discovery and documentation

“[I like] The easy to use interface and the speed of finding the relevant assets that you're looking for in your database. I also really enjoy the score given to each table, [which] lets you prioritize the results of your queries by how often certain data is used.” - Michal P., Head of Data