Fixed macro
This commit is contained in:
parent
e4d19b85e8
commit
720185f235
3 changed files with 68 additions and 56 deletions
20
macros/return_capped_value.sql
Normal file
20
macros/return_capped_value.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
This macro caps a given value between a specified bottom and top limit,
|
||||
returning `NULL` if the input value is `NULL`.
|
||||
|
||||
It uses the `LEAST` and `GREATEST` SQL functions to enforce the caps while
|
||||
preserving the `NULL` values in the input.
|
||||
|
||||
Parameters:
|
||||
- `value`: The value to be capped.
|
||||
- `cap_bottom`: The minimum limit for the value.
|
||||
- `cap_top`: The maximum limit for the value.
|
||||
|
||||
*/
|
||||
{% macro return_capped_value(value, cap_bottom, cap_top) %}
|
||||
CASE
|
||||
WHEN {{ value }} IS NULL THEN NULL
|
||||
ELSE LEAST({{ cap_top }}, GREATEST({{ cap_bottom }}, {{ value }}))
|
||||
END
|
||||
{% endmacro %}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue