Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Statements

Pre-statements, post-statements, and on-virtual-update statements, and how to set defaults for them at the project level.

Statements run SQL commands at specific points during model execution. Run code before your query, after it completes, or when views are created.

Why use statements? Use them for:

  • Setting session parameters (timeouts, memory limits).

  • Loading UDFs or creating temporary tables.

  • Creating indexes or clustering.

  • Running data quality checks.

  • Logging anomalies or errors.

  • Granting permissions on views.

Define statements at the model level (for specific needs) or at the project level via model_defaults (for consistent behavior across all models).

Statement types:

  • Pre-statements: run before the main model query executes.

  • Post-statements: run after the main model query completes.

  • On-virtual-update statements: run when views are created or updated in the virtual layer.

Model defaults

Define statements at the project level using model_defaults in your configuration. Use this for common behavior across all models, like session timeouts or default permissions.

How it works: default statements run first, then model-specific statements. If you set a default timeout in model_defaults and a model-specific timeout in a model, the model-specific one runs after and can override the default.

Pre-statements

Pre-statements run before your main model query executes. Use them to set up the environment your query needs.

Common use cases:

  • Loading JARs or UDFs that your query uses.

  • Creating temporary tables or caching data.

  • Setting session parameters (timeouts, memory, etc.).

  • Initializing variables or settings.

Pre-statements run in the setup phase before your main query.

Post-statements

Post-statements run after your model query completes. Use them for cleanup, optimization, or validation tasks.

Important: when you use post-statements in SQL models, your main query must end with a semicolon. This tells Vulcan where the query ends and the statements begin.

Common use cases:

  • Creating indexes or clustering (for query performance).

  • Running data quality checks or validations.

  • Logging anomalies or errors to tracking tables.

  • Conditional table alterations (like setting retention policies).

The "cleanup and optimization" phase after your data is loaded.

On-virtual-update statements

On-virtual-update statements run when views are created or updated in the virtual layer. This happens after your model's physical table is created and the view pointing to it is set up.

Common use cases:

  • Granting permissions on views (so users can query them).

  • Setting up access controls or row-level security.

  • Applying column masking policies.

  • Any view-level configuration.

The "access control" phase: who can see what.

Note: these statements run at the virtual layer, so table names (including @this_model) resolve to view names, not physical table names.

Use ON_VIRTUAL_UPDATE_BEGIN and ON_VIRTUAL_UPDATE_END to define these statements:

Use the on_virtual_update argument in the @model decorator:

Complete example

Here's a complete example showing all statement types:

Useful macros and variables

Macro/Variable
Description

@this_model

References the current model's table/view.

@runtime_stage

Current execution stage: 'creating', 'evaluating', or 'testing'.

@IF(condition, statement)

Conditionally execute a statement.

@start_date, @end_date

Time range macros for incremental models.

{{ this_model }}

Jinja equivalent of @this_model.

For more on macros, see the Macro Variables documentation.

Last updated

Was this helpful?