TO_QUERY
functionsupportedQueries & DMLReturns a result set based on SQL text and an optional set of arguments that are passed to the SQL text if it is parameterized. The function compiles the SQL text as the definition of a subquery in the FROM clause. When writing an application or a stored procedure, you can call this function to construct a SQL statement. Note This function can include user input in query statements, which has potential security risks, such as SQL injection. If inputs to the function come from external sources, make sure they are validated. For more information, see SQL injection. See also: Constructing SQL at runtime
Syntax
TO_QUERY( SQL => '<string>' [ , <arg> => '<value>' [, <arg> => '<value>' ...] ] )
Parameters
| Name | Required | Description |
|---|---|---|
SQL => 'string' | required | String representation of the subquery. |
arg => 'value' | optional | Bind variables passed to the SQL string. |
Returns
Returns the result set produced by the execution of the specified SQL text or NULL. If any argument is NULL, the function returns NULL without reporting any error.
Usage notes
- All arguments must be one of the following: Constant strings.
- SQL variables or Snowflake Scripting variables that resolve to strings.
- If you need to convert a string passed in an argument to a different data type, you can use a conversion function in the SQL string to convert the string to another data type.
- The set of columns defining the result set is derived from the SELECT list of the compiled SQL statement.
- The function is valid only in the FROM clause of a SQL statement.