So as part of some stuff I have been doing in my day job I have built some useful and decided I should build a basic function in Snowflake before moving onto something more complicated with table functions and the like. So my basic function is one that accepts parameters and uses this to determine if an activity is +- 1 standard deviation from the average over all time for that activity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function f_exercise_out(p_daily_total number, p_avg number, p_std number , p_coeff number) | |
returns varchar2(1) | |
as | |
$$ | |
select case when p_daily_total = 0 then 'L' | |
when p_daily_total < (p_avg - (p_std*p_coeff)) THEN 'L' | |
when p_daily_total > (p_avg + (p_std*p_coeff)) THEN 'U' | |
else 'W' | |
END | |
$$ | |
; |
I actually call the code above using dbt to create the views and tables and will show that in my next post. For now here is a screen shot of me calling that function using jinja scripting to create the different function calls.
Comments
Post a Comment