UD">

User-defined functions (UDFs) let you extend the system to perform operations that are not available through the built-in, system-defined functions provided by Snowflake.

Snowflake currently supports the following languages for writing UDFs:

This guide will walk you through setting up Snowflake and getting familiar with

Prerequisites

If you are not familiar with the Snowflake User Interface, then please watch the video below.

What You'll Learn

What You'll Need

What You'll Build

First, we'll go over how to create your Snowflake account and manage user permissions.

Create a Snowflake Account

Snowflake lets you try out their services for free with a trial account. Follow the prompts to activate your account via email.

If you already have a Snowflake account, you can use it. You just need a role with permission to create a database.

Access Snowflake's Web Console

https://<your-account-name>.snowflakecomputing.com/console/login

Log in to the web interface from your browser. The URL contains your account name and potentially the region.

Changing your role

Snowflake_SwitchRole_DemoUser-image

Switch the account role from the default SYSADMIN to ACCOUNTADMIN. This is not required, but will ensure your web UI aligns with the screen shots in this lab.

With your new account created and the role configured, you're ready to begin creating database objects in the following section.

With your Snowflake account at your fingertips, it's time to create the database objects.

Within the Snowflake web console, navigate to Worksheets and use a fresh worksheet to run the following commands.

1. Create a new Database

create or replace dat

Snowflake 계정에 쉽게 접근할 수 있으니 데이터베이스 오브젝트를 생성할 시간입니다.

Snowflake 웹 콘솔 내에서 Worksheets로 이동한 다음 새로운 워크시트를 사용하여 다음 명령을 실행합니다.

1. 새로운 데이터베이스 생성

create or replace database udf_db;

위 명령으로 udf_db라는 새로운 데이터베이스를 구축합니다.

Snowflake_udf_CreateDB-image

Positive : ResultsDatabase UDF_DB successfully created라는 상태 메시지를 표시해야 합니다.

2. 새로운 스키마 생성

create schema if not exists udf_schema_public;

위 명령을 사용하여 udf_schema_public이라는 스키마를 생성합니다.

Snowflake_udf_CreateSchema-image

Positive : ResultsSchema UDF_SCHEMA_PUBLIC successfully created라는 상태 메시지를 표시해야 합니다.

3. 새로운 테이블에 샘플 데이터 복사

create or replace table udf_db.udf_schema_public.sales 
  as
    (select * from snowflake_sample_data.tpcds_sf10tcl.store_sales sample block (1));

‘sales'라는 테이블을 생성하고 이 명령으로 매출 데이터를 가져옵니다. 샘플 데이터를 가져오는 데 이전 단계에서 보다 더 긴 실행 시간이 소요될 것입니다.

With the database primed with sample sales data, we're almost ready to try creating a scalar UDF. Before diving in, let's first understand more about UDF naming conventions.