Skip to main content
Constants are string values that can be defined once in a model file and referenced throughout your model using @{constant_name} syntax. Constants are resolved before other template processing (Mustache and field references) when a query executes or a link renders, making them ideal for values that need to be centrally managed and consistently applied across your model. For example:
  • Database schema names that may differ between environments
  • Common URL patterns for data links
  • Repeated string values that you want to maintain in a single location
  • Configuration values that can be dynamically referenced
Constants are also inherited by shared extension models.

Syntax

constants:
  <constant_name>:
    value: <string_value>

Properties

constants
object
A map of constant definitions where each key is the constant name. Names must be unique within the model.

Examples

Dynamic schema reference

Use constants to reference schema names that may vary across environments. Define the constants in the model file:
Model file
constants:
  base_schema:
    value: analytics_prod
  staging_schema:
    value: analytics_staging
And then reference the constants, such as in the following view file:
View file
sql: |
  SELECT *
  FROM @{base_schema}.users
Create link patterns that include field references. Define the constants in the model file:
Model file
constants:
  google_search:
    value: "https://www.google.com/search?q=${users.country}"
  user_profile:
    value: "https://example.com/profile/${users.user_id}"
And then reference the constants in fields, such as the following dimensions:
Dimensions in a view
dimensions:
  country:
    sql: country
    link: "@{google_search}"
  user_id:
    sql: user_id
    link: "@{user_profile}"