Troubleshooting SQL UDFs¶
This topic provides troubleshooting information about SQL UDFs (user-defined functions).
Troubleshooting¶
Tips¶
If using a SQL UDF in a masking policy, ensure the data type of the column, UDF, and masking policy match.
Error message: Unsupported subquery type¶
- Cause:
If a UDF contains a query expression, then the UDF can act as a subquery. If a subquery is passed a column name, then the subquery can act as a correlated subquery. If a correlated subquery violates the Snowflake rules for correlated subqueries, then the user gets the error message
Unsupported subquery type. The example below shows an invalid correlated subquery, and how a UDF can act like a similar invalid correlated subquery.Create a pair of tables and load data into them:
The following SQL statement contains a correlated subquery that does not follow Snowflake rules. This code causes an
Unsupported subquery typeerror:The code below creates and then calls a subquery-like UDF in a way that creates a correlated subquery similar to the one shown above:
- Solution #1:
If the UDF contains a query expression, then call the UDF only in ways consistent with the rules for subqueries.
For example, the following statement calls the UDF with a constant rather than with a column name, so the UDF does not act like a correlated subquery:
- Solution #2:
In some cases, you can re-write the UDF to achieve the same goal a different way. A correlated subquery is allowed if the subquery can be statically determined to return one row. The following UDF uses an aggregate function and therefore returns only one row: