TO_QUERY

functionsupportedQueries & DML

docs.snowflake.com ↗

Table functions

Returns 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

NameRequiredDescription
SQL => 'string'requiredString representation of the subquery.
arg => 'value'optionalBind 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