FINALLY clause cleans up temporary resources.
For details about data flow syntax and supported statements, see Data Flows.
Prerequisites
Before you begin, ensure that you have:- A running Ocient deployment with access to execute SQL statements.
- The
CREATE TABLEandINSERTprivileges on the target schema.
Prepare the Target Table
For the purposes of this tutorial, assume a source staging table namedstaged_events with these columns.
Create the target table that receives validated data.
SQL
Build and Execute the Validation Pipeline
1
Understand the Validation Checks
Before building the data flow, define the validation rules that the source data must satisfy. This example enforces three rules:
- Row count check — The staging table must contain at least one row.
- NULL check — No rows can have a NULL
user_idcolumn value. - Value range check — No rows can have a
payload_sizecolumn value exceeding 10,000,000 bytes.
2
Build the Validation Data Flow
Create a void data flow that executes each validation check in sequence. If all checks pass, the data flow loads the staged data into the production table.If any
SQL
RAISE statement executes, the data flow aborts immediately and does not insert any data into the events table. The FINALLY clause still executes, dropping the staging table regardless of whether the load succeeded or failed.3
Use Multiple Severity Levels with the ELSEIF Element
You can use the
ELSEIF element to implement tiered validation where different conditions produce different error messages or take different actions. This example checks row count thresholds and raises warnings at different levels.SQL
4
Combine Validation with Error Handling
You can wrap the entire validation and load sequence in the The
TRY and EXCEPTION WHEN elements to catch unexpected errors. This example logs the error for diagnostics, then re-raises it so the data flow still aborts on failure.SQL
@SQLERRM variable contains the error message from the caught exception, including the message from any RAISE statement. The @SQLSTATE variable contains the corresponding SQLSTATE code.
