avatarChristianlauer

Summary

Snowflake has introduced new SQL array functions to enhance the manipulation of semi-structured data, including ARRAY_GENERATE_RANGE and ARRAY_REMOVE_AT.

Abstract

Snowflake's recent update in May has brought forth new SQL functions aimed at improving the handling of arrays within semi-structured data. These functions, namely ARRAY_GENERATE_RANGE and ARRAY_REMOVE_AT, provide users with more flexibility and efficiency when generating dummy data or performing data transformations. The ARRAY_GENERATE_RANGE function simplifies the creation of arrays with sequential elements, demonstrated by an example generating an array from 2 to 5. The ARRAY_REMOVE_AT function allows for the removal of specific elements within an array, which is particularly useful for data analysts and engineers in refining datasets. These enhancements are part of Snowflake's ongoing efforts to empower data-driven decision-making and streamline data change data (CDC) pipelines and data integration processes.

Opinions

  • The author suggests that the new array functions are a significant addition to Snowflake's SQL capabilities, especially for those working with semi-structured data.
  • The functions ARRAY_GENERATE_RANGE and ARRAY_REMOVE_AT are considered "very handy" for tasks such as generating dummy data and removing specific values within arrays, respectively.
  • The author implies that these updates are part of Snowflake's commitment to providing tools that enable businesses to make data-driven decisions more effectively.
  • The article hints at the broader context of Snowflake's continuous development, mentioning other updates like the ServiceNow Connector and Streams on Views, which are also aimed at enhancing data management and integration.
  • The author encourages readers to explore the official Snowflake documentation to gain a deeper understanding of the new functions and their potential applications.

New SQL Array Functions for Snowflake

How Snowflake is bringing new Options when working with Semi-Structured Data

Photo by Joel & Jasmin Førestbird on Unsplash

Since I haven’t reported anything about Snowflake for a long time, there are now interesting news about SQL functionalities if you work with arrays, so besides structured data also with semi-structured data.

With other updates this May, Snowflake has also implemented the following functions when working with arrays[1]:

New Array Functions in Snowflake — Image by Snowflake[1]

So here is a small example with the ARRAY_GENERATE_RANGE function, which is very handy if you have to generate dummy data for example[2]:

SELECT ARRAY_GENERATE_RANGE(2, 6);
+----------------------------+
| ARRAY_GENERATE_RANGE(2, 6) |
|----------------------------|
| [                          |
|   2,                       |
|   3,                       |
|   4,                       |
|   5                        |
| ]                          |
+----------------------------+

This example returns an ARRAY containing a range of numbers starting from 2 and ending before 6.

Also an inserting new function is the ARRAY_REMOVE_AT function. With that, you can remove certain values within the array. This could be interesting for Data Analysts and Scientists during data transformations as well as for Snowflake Data Engineers when implementing and transforming data[3].

+-------------------------------+
| ARRAY_REMOVE_AT([3, 5, 8], 0) |
|-------------------------------|
| [                             |
|   5,                          |
|   8                          |
| ]                             |
+-------------------------------+

In this example, I used the function to remove the first element. In this case, it would be the 3.

If you want to dive further into the matter and learn more about the functions and the parameters you can use, feel free to use the official docs of Snowflake linked below. I hope that this short article could help you with telling that Snowflake has extended the functionality for working with arrays and that you can use the example SQLs as a blueprint.

Sources and Further Readings

[1] Snowflake, SQL Updates (2023)

[2] Snowflake, ARRAY_GENERATE_RANGE (2023)

[3] Snowflake, ARRAY_REMOVE_AT (2023)

Data Science
Programming
Snowflake
Sql Server
Technology
Recommended from ReadMedium