EXECUTE
Description
The
EXECUTEIMMEDIATEstatement builds and runs a dynamic SQL statement in a single operation.Native dynamic SQL uses the
EXECUTEIMMEDIATEstatement 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
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:
Related EWIs
SSC-EWI-0027: Variable with invalid query.
SSC-EWI-0030: The statement below has usages of dynamic SQL.
Last updated
