A directory you will use as the CLI project root (this tutorial uses ~/tutorial-sql-models; replace it with your path)
At least one Reverse ETL source in the RudderStack dashboard for the warehouse you query — RudderStack uses that connection to resolve account IDs (see List warehouse accounts)
RudderStack recommends using a workspace-level Service Access Token for authentication.
Any action authenticated by a Personal Access Token will break if you’re removed from the organization or RudderStack makes a breaking change to your permissions.
If you already manage Data Catalog or Tracking Plan YAML in another folder, you can add SQL model files there instead — Rudder CLI discovers .yaml / .yml files recursively under the path you pass to -l / --location.
3. List warehouse accounts
Each SQL model references an account_id for the warehouse connection. List accounts linked to your workspace:
rudder-cli workspace accounts list
Pick the account ID that matches your Reverse ETL warehouse setup. You will use it in the YAML spec in the next sections.
You need a configured Reverse ETL source in the dashboard so warehouse credentials exist for that account.
4. Create a new SQL model
Add a YAML file (for example ~/tutorial-sql-models/sql-models/product-purchases.yaml) with a retl-source-sql-model resource. Replace account_id with the value from List warehouse accounts.
version:"rudder/v1"kind:"retl-source-sql-model"metadata:name:"product-purchases-model"spec:id:"product-purchases-model"display_name:"Product Purchases SQL Model"primary_key:"user_id"description:"SQL model for product purchases"source_definition:"postgres"enabled:trueaccount_id:"YOUR_ACCOUNT_ID"sql:| SELECT
user_id,
event_name,
event_type,
timestamp,
properties
FROM
user_events
WHERE
timestamp >= CURRENT_DATE - INTERVAL '180 days'
ORDER BY
timestamp DESC
Query shape
Inline SQL: use sql: | as above.
External file: use file: "./sql/my-query.sql" instead of sql — use one of sql or file, not both.
source_definition values (examples): postgres, mysql, snowflake, redshift, bigquery, databricks, trino. See the SQL Model YAML reference for the full spec.
Rudder CLI writes YAML under your project (and a .sql file when you use --sql-location). The metadata.import section maps your local_id to the workspace remote_id so later apply calls stay aligned.
Finish linking the import
Validate and apply so the CLI project owns the resource:
This checks SQL syntax for the warehouse, connectivity to the account, required fields, and that the query can run (limited execution), as described in Validate SQL model resources.
Preview query results
Runs the query and prints sample rows (use your model’s spec.id):
Useful flags: -l / --location for the project root, --limit for row cap (default 100), -j for JSON output, --interactive=false for scripts. See Validate and preview your models for examples and troubleshooting.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.