sqlmesh
sqlmesh copied to clipboard
Feature request: support user-defined macros written as SQL
Currently, user-defined macros need to be defined as python. An alternative SQL-based syntax would be more consistent with MODEL
and AUDIT
. That is, having a MACRO
function to define user-defines macros in .sql
files:
MACRO(
name forall,
defaults (
condition NULL
)
);
SELECT *
FROM @this_model
WHERE
@AND(
@REDUCE(@criteria, (l,r) -> l AND r),
@condition,
)
For supporting named arguments, perhaps a more general arguments
could work, i.e.: you'd have to define each argument and its default value (and maybe its type for coercion)?:
MACRO(
name accepted_range,
arguments (
min_v NULL,
max_v NULL,
inclusive TRUE,
condition NULL,
)
);
...