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
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
- Part-02 User Defined Function in Snowflake SQLs
- Part-02 JavaScript & SQL User Defined Function in Snowflake SQLs
- Part-03 Strict Property User Defined Function in Snowflake SQLs
- Part-04 Not Null Return User Defined Function in Snowflake SQLs
- Part-05 Secure User Defined Function in Snowflake SQLs
- Part-06 Inbuilt Vs. User Defined Function in Snowflake SQLs
- Part-07 Table User Defined Function in Snowflake SQLs
- Part-08 Method Overloading SQL Script
- Part-09 Java User Defined Function SQL & Java Code