1
votes

We have a requirement wherein the result returned by a select statement should be dynamic based on the select query executed. So, we are leaning towards a solution of calling a stored procedure within a function that will be used in the select statement.

Question is: can we call a stored procedure from a function in Snowflake? And what would be the syntax be?

Please share.

1
You can't call a stored procedure from a UDF. Refer to the usage notes, esp this part "because the call cannot be part of an expression": docs.snowflake.com/en/sql-reference/sql/call.html#usage-notes. You may be able to use a User Defined Table Function (UDTF) depending on what you need to do. Can you elaborate?Greg Pavlik

1 Answers

1
votes

I've done similar things to this. Although you can't call a stored procedure from a UDF you can call a stored procedure from another stored procedure.

It's also possible to call a stored procedure with a task and pass the return value of the stored procedure to the task to then pass that to another stored procedure call.

From your opening comment, you might be able to solve your problem using an if statement in javascript to execute a select statement based on your rules.

Can you work up a basic example of the query and what you are trying to do?