I have a case when using the Snowflake API. We have a bunch of materialized views, multiple for each customer of ours. When using the API, we would like to use functions or stored procedures to produce a result in runtime, and taking the customer ID as a parameter. This parameter would be used to fetch data from the correct views, to avoid have functions for each client. However, I'm running into some issues:
- SQL UD(T)F isn't working, since it seems that you can't use a parameter in the FROM clause. Neither can you use variables or running multiple statements if I understood it correctly.
- JavaScript UD(T)F isn't working since your not allowed to execute statements.
- Stored procedures are working for single values (which is one use case), but not for returning a table. It can return a VARIANT, but that would add work in the service consuming the API which we would like to avoid.
Do you have any suggestions on how to to achieve the result we're after? We could create pre-calculated views with the results we're after, but that would result in a ton of views since we need other parameters as well in the API for a dynamic (filtered) result. Therefore a function-based approach seems much more neat and easier to maintain.
Thanks for your help and support!