- Void data flow — Executes statements for side effects such as creating tables, inserting data, or performing cleanup. A void data flow does not return a result set.
- Query data flow — Executes statements and returns a result set using a
RETURN SELECTstatement.
Use Cases
Data flows are useful for these scenarios:- Stage and Transform Data with Data Flows — Create staging tables, apply transformations across multiple steps, load into final tables, and clean up with the
FINALLYclause. - Build Iterative Queries with Data Flows — Use
WHILEloops with theMAX ITERATIONSkeyword for convergence algorithms, graph traversals, or accumulation patterns. - Validate Data Before Loading with Data Flows — Use
IF,ELSEIF, andRAISEkeywords as guard clauses to verify data quality before committing a load.
Syntax
This code block shows the complete syntax for data flows.SQL
RETURN SELECT statement with no preceding statements.
The <initial_statement_list> and <statement_list> placeholders represent the following elements.
Initial Statement List (<initial_statement_list>)
Appears at the top level of the data flow body and accepts declarations and flow statements. You can use DECLARE statements only in this list, not inside loops, IF blocks, or a FINALLY clause.
Statement List (<statement_list>)
Appears inside loops, IF branches, and FINALLY clauses. Supports the same elements as the <initial_statement_list> except for the DECLARE element.
The following table describes other structural elements.
Temporary Tables
Temporary tables use a# prefix in their names, and the database scopes them to the data flow block. The database automatically drops temporary tables when the data flow completes, so you do not need an explicit DROP TABLE SQL statement in a FINALLY clause.
Syntax
SQL
# prefix and uses it for intermediate processing. The database drops the temporary table automatically when the data flow completes.
SQL
BEGIN DATAFLOW
A void data flow executes one or more statements for their side effects. This data flow does not return a result set. SyntaxSQL
# prefix), filters and stages data, and loads it into a final table. The database drops the temporary table automatically when the data flow completes.
SQL
BEGIN QUERY DATAFLOW
A query data flow executes statements and returns a result set. TheRETURN SELECT statement must appear after all other statements and before the optional FINALLY clause.
Syntax
SQL
total variable, assigns it the row count from the orders table, and returns the result.
SQL
DECLARE
Declares a script variable with a specified data type and an optional initial value. You can useDECLARE statements only at the top level of the data flow body, not inside loops, IF clauses, or FINALLY clauses.
Syntax
SQL
Example
This example declares variables with different data types and initialization options and returns their values. The
counter variable has the BIGINT type and 0 as the default value. The name variable has the VARCHAR type and default as the default string. Also, the threshold variable has the DOUBLE type and a non-NULL value with 0.95 as the default value.
SQL
Supported Variable Data Types
This table lists all data types supported for data flow variables. For details on Ocient data types, see Data Types.
Type synonyms:
CHAR and VARCHAR map to STRING. INTEGER maps to INT. TINYINT maps to BYTE.
Data flow variables do not support the
VARBINARY, MATRIX, and FUNCTION data types.SET
Assigns a new value to a previously declared variable. SyntaxSQL
SQL
18
WHILE
Repeats a block of statements while a condition evaluates totrue. You can use the optional MAX ITERATIONS clause to set an upper bound on the number of iterations.
Syntax
SQL
Example
This example uses a
WHILE loop with the MAX ITERATIONS clause to sum integers from one to 10.
SQL
IF, ELSEIF, and ELSE
Executes statements conditionally. The data flow evaluates conditions in order and executes the first matching branch. You can chain zero or moreELSEIF clauses. The optional ELSE clause executes if no condition matches. Each branch contains a statement list <statement_list>.
Syntax
SQL
Example
This example uses chained
ELSEIF clauses to map a numeric value to a string label.
SQL
two
FOR
Iterates using either C-style or iterator-style syntax. Both styles support the optionalMAX ITERATIONS clause. The loop body contains a statement list <statement_list>.
C-Style FOR
SyntaxSQL
The increment statement executes after each iteration, including iterations that execute the
CONTINUE element.
Example
This example uses a C-style FOR loop to sum integers from one to five.
SQL
15
Iterator-Style FOR
Iterates over the rows returned by a query. The source query must return exactly one column. SyntaxSQL
Example
This example iterates over the rows returned by a query and accumulates a sum.
SQL
55
BREAK
Immediately exits the innermost enclosing loop (WHILE or FOR). In nested loops, the BREAK element exits only the innermost loop. Using the BREAK element outside a loop produces a runtime error.
Syntax
SQL
WHILE loop early when the counter reaches 3.
SQL
3
CONTINUE
Skips the remainder of the current loop iteration and proceeds to the next iteration. In C-styleFOR loops, the increment statement still executes before the next condition check. Using the CONTINUE element outside a loop produces a runtime error.
Syntax
SQL
@i equals 3, so the sum excludes that value.
SQL
12 (1 + 2 + 4 + 5; skips the iteration where @i = 3)
RAISE
Throws a user-defined error message and aborts the data flow. If theFINALLY clause is present, the database executes it before the error propagates.
Syntax
SQL
Example
This example checks the row count in a staging table and raises an error if the table contains no records.
SQL
TRY and EXCEPTION WHEN
Catches errors raised by statements in aTRY element. You define one or more EXCEPTION WHEN handlers that match the specific SQLSTATE code or all errors using the OTHERS string. Inside a handler, the @SQLERRM and @SQLSTATE variables expose the caught error message and SQLSTATE code. Both the TRY body and each handler contain a statement list <statement_list>.
Syntax
SQL
Example
This example catches any error from an
INSERT SQL statement and re-raises it.
RAISE @SQLERRM forwards the original error message but not the original SQLSTATE code. The re-raised error uses a generic exception code.SQL
FINALLY
Defines a cleanup statement that always executes when the data flow completes, regardless of whether an error occurred. Use theFINALLY clause to drop staging tables, release resources, or perform other cleanup operations that must execute even after an error.
Syntax
SQL
FINALLY clause executes even after a RAISE statement or other runtime error.
Example
This example uses the FINALLY clause to ensure that the data flow drops the staging table even if an error occurs during processing. Unlike temporary tables (which the database drops automatically), regular staging tables require explicit cleanup.
SQL
RETURN
Returns a result set from a query data flow. TheRETURN clause must appear after all other statements and before the optional FINALLY clause. Only query data flows (using BEGIN QUERY DATAFLOW) support the RETURN clause.
Syntax
SQL
#filtered and returns the result set sorted by the confidence column.
SQL

