Variables
Reference for Vulcan's predefined macro variables: temporal variables like @execution_ds, runtime variables like @runtime_stage and @this_model, and before_all/after_all variables.
Macro variables are placeholders that Vulcan replaces with actual values when it renders your SQL. They make your queries dynamic: instead of hardcoding values, use variables that change based on context.
Instead of writing WHERE date > '2023-01-01' and updating it every day, write WHERE date > @execution_ds to use today's date automatically.
A quick example
A query that filters by date. Without macros:
SELECT *
FROM table
WHERE my_date > '2023-01-01'Changing the date means editing the query. That's tedious and error-prone.
Use a macro variable to make it dynamic:
SELECT *
FROM table
WHERE my_date > @execution_dsThe @ symbol tells Vulcan "this is a macro variable, replace it with a value before executing." The @execution_ds variable is predefined; Vulcan sets it to the date when execution started.
Run this model on February 1, 2023, and Vulcan renders it as:
SELECT *
FROM table
WHERE my_date > '2023-02-01'The date updates automatically every time you run it. No manual editing.
Vulcan ships with predefined variables like this. You can also create custom variables for specific needs, covered in the macro system pages.
Predefined variables
Vulcan provides predefined variables that are automatically available in your models. Most relate to time (dates, timestamps, and more), since time-based logic is common in data models.
The time variables follow a consistent naming pattern: a prefix (like start, end, or execution) plus a postfix (like ds, ts, or epoch) creates variables like @start_ds or @execution_epoch.
Temporal variables
Vulcan uses Python's datetime module under the hood and follows the standard Unix epoch (starting January 1, 1970).
Prefixes indicate the time period the variable represents:
start: the beginning of the time interval for this model run (inclusive).end: the end of the time interval for this model run (inclusive).execution: the exact timestamp when the execution started.
Postfixes indicate the format of the value:
dt: a Python datetime object that becomes a SQLTIMESTAMP.dtntz: a Python datetime object that becomes a SQLTIMESTAMP WITHOUT TIME ZONE.date: a Python date object that becomes a SQLDATE.ds: a date string formatted as'YYYY-MM-DD'(for example,'2023-02-01').ts: an ISO 8601 datetime string:'YYYY-MM-DD HH:MM:SS'.tstz: an ISO 8601 datetime string with timezone:'YYYY-MM-DD HH:MM:SS+00:00'.hour: an integer from 0-23 representing the hour of the day.epoch: an integer representing seconds since Unix epoch.millis: an integer representing milliseconds since Unix epoch.
All temporal variables:
dt (datetime objects):
@start_dt@end_dt@execution_dt
dtntz (datetime without timezone):
@start_dtntz@end_dtntz@execution_dtntz
date (date objects):
@start_date@end_date@execution_date
ds (date strings):
@start_ds@end_ds@execution_ds
ts (timestamp strings):
@start_ts@end_ts@execution_ts
tstz (timestamp strings with timezone):
@start_tstz@end_tstz@execution_tstz
hour (hour integers):
@start_hour@end_hour@execution_hour
epoch (Unix epoch seconds):
@start_epoch@end_epoch@execution_epoch
millis (Unix epoch milliseconds):
@start_millis@end_millis@execution_millis
Runtime variables
Beyond time, Vulcan provides variables that give you information about the current execution context:
@runtime_stage: a string indicating the current stage. Use it to conditionally run code based on whether you're creating tables, evaluating queries, or promoting views. Possible values:'loading': project is being loaded into Vulcan's runtime.'creating': model tables are being created for the first time.'evaluating': model query is being evaluated and data inserted.'promoting': model is being promoted (view created in virtual layer).'demoting': model is being demoted (view dropped from virtual layer).'auditing': an audit is being run.'testing': model is being evaluated in a unit test context.
See pre/post-statements.
@gateway: the name of the current gateway (your database connection).@this_model: the physical table name that the model's view selects from. Use it to create generic assertions. In on_virtual_update statements, it contains the qualified view name instead.@model_kind_name: the name of the current model kind (such as'FULL'or'INCREMENTAL_BY_TIME_RANGE'). Use it to control physical properties in model defaults based on the model kind.
Before all and after all variables
These variables are available in before_all and after_all statements and in any macros called within those statements:
@this_env: the name of the current environment.@schemas: a list of schema names in the virtual layer for the current environment.@views: a list of view names in the virtual layer for the current environment.
Use them for setup or cleanup operations that depend on the environment context.
Last updated
Was this helpful?