Administrator

How to use not-null property in Snowflake UDFs

How to use not-null property in Snowflake UDFs

User Defined Functions in Snowflake Video

You can watch the complete hands on video tutorial

Step-4: SQL Construct

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use role sysadmin;
use database ttips;
use schema udfs;

-- creating a javascript function with not null specification
create or replace function not_null_udf()
returns string not null
language javascript
as
$$
    return null
$$;

-- lets see how does it capture
desc function not_null_udf();

-- call the function and observer the behaviour
select not_null_udf();

-- lets fix it
create or replace function not_null_udf()
returns string null
language javascript
as
$$
    return null
$$;

-- rerun the function
select not_null_udf();

-- so this is how it works. This is very similar to strict keyword in stored procedure
-- which we covered in previous chapter (ch-21.1)
-- https://youtu.be/CsH2sB6gwlw

-- lets see if this works in SQL language
create or replace function not_null_sql_udf()
RETURNS string
comment = 'this is simple not null enforcement test for SQL function'
as
$$
    select null
$$;

desc function not_null_sql_udf();
select not_null_sql_udf();

-- now add the paramter and see the behaviour
-- it allows to add the keyword but does not enforce.

All SQL Scripts - Part 01 to Part 09

  1. Part-02 User Defined Function in Snowflake SQLs
  2. Part-02 JavaScript & SQL User Defined Function in Snowflake SQLs
  3. Part-03 Strict Property User Defined Function in Snowflake SQLs
  4. Part-04 Not Null Return User Defined Function in Snowflake SQLs
  5. Part-05 Secure User Defined Function in Snowflake SQLs
  6. Part-06 Inbuilt Vs. User Defined Function in Snowflake SQLs
  7. Part-07 Table User Defined Function in Snowflake SQLs
  8. Part-08 Method Overloading SQL Script
  9. Part-09 Java User Defined Function SQL & Java Code