EXECUTE

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Description

The EXECUTE IMMEDIATE statement builds and runs a dynamic SQL statement in a single operation.

Native dynamic SQL uses the EXECUTE IMMEDIATE statement to process most dynamic SQL statements. (Redshift Language Reference EXECUTE Statement)

Grammar Syntax

EXECUTE command-string [ INTO target ];

Sample Source Patterns

Concated Example

Input Code

IN -> Redshift_01.sql
CREATE OR REPLACE PROCEDURE create_dynamic_table(table_name VARCHAR) 
AS $$ 
DECLARE 
sql_statement VARCHAR; 
BEGIN 
sql_statement := 'CREATE TABLE IF NOT EXISTS ' || table_name || ' (id INT, value VARCHAR);'; 
EXECUTE sql_statement; 
END;
$$ LANGUAGE plpgsql; 

Output Code

Function Transformation

Input Code

Output Code

Error In Query Parsing

Input Code

Output Code

INTO Clause

Input Code

Output Code

Known Issues

1. Execution results cannot be stored in variables.

SnowScripting does not support INTO nor BULK COLLECT INTO clauses. For this reason, results will need to be passed through other means.

2. Dynamic SQL Execution queries may be marked incorrectly as non-runnable.

In some scenarios there an execute statement may be commented regardless of being safe or non-safe to run so please take this into account:

  1. SSC-EWI-0027: Variable with invalid query.

  2. SSC-EWI-0030: The statement below has usages of dynamic SQL.

Last updated