Models may reference "external" tables that have been created outside SQLMesh. These external tables are captured in SQLMesh as models with a unique "external" kind. Each external model retains metadata about a table it represents.
This metadata allows SQLMesh to provide column-level lineage and data type information for models that reference external tables.
Generating external models schema
External models are defined in the
schema.yaml file in the SQLMesh project's root folder.
You can create this file by either (i) allowing SQLMesh to fetch information about external tables with the
create_external_models CLI command or (ii) writing the YAML by hand.
Consider this example model that queries an external table
The following sections demonstrate how to create an external model containing metadata about
external_db.external_table, which contains columns
Instead of creating the
schema.yaml file manually, SQLMesh can generate it for you. The create_external_models CLI command does exactly this.
The command locates all external tables referenced in your SQLMesh project, fetches their schemas (column names and types), and then stores them in the
Writing YAML by hand
The following example demonstrates a typical content of the
All the external models in a SQLMesh project are stored in a single