SqlModel
SQL Models are queries that return base data from a SQL source. The
resulting columns are referenced by Insights via ${ref(model).column}
field references in their ?{ ... } slot bindings.
SQL Models can also carry their slice of the semantic layer: model-scoped
metrics (aggregate calculations) and dimensions (row-level calculated
fields) defined on the model are reusable anywhere the model can be
referenced.
Example
models:
- name: orders
source: ref(sql_source)
sql: select * from orders
models:
- name: orders
source: ref(sql_source)
sql: select * from orders
metrics:
- name: total_revenue
expression: sum(amount)
dimensions:
- name: order_month
expression: date_trunc('month', created_at)
Attributes
| Field | Type | Default | Description |
|---|---|---|---|
| path | string | None | A unique path to this object |
| name | string | None | The unique name of the object across the entire project. |
| file_path | string | None | The path to the file that contains the object definition. |
| sql | string | None | The SQL query that returns this model's base data from its source. |
| source | Any of: BigQuerySource, CSVFileSource, ClickhouseSource, DuckdbSource, ExcelFileSource, MysqlSource, PostgresqlSource, RedshiftSource, SnowflakeSource, SqliteSource, string or string | None | A source object defined inline or a ${ ref() } to a source. Override the defaults.source_name |
| metrics | Array of Metric | [] | A list of model-scoped metrics that aggregate data from this model. |
| dimensions | Array of Dimension | [] | A list of computed dimensions (row-level calculations) for this model. |