<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>RudderStack Docs – Manage SQL Models using Rudder CLI</title><link>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/</link><description>Recent content in Manage SQL Models using Rudder CLI on RudderStack Docs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/index.xml" rel="self" type="application/rss+xml"/><item><title>Archive: Create New SQL Model Resource using Rudder CLI</title><link>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/</guid><description>
&lt;p>This guide walks you through the process of creating a new SQL model resource from scratch using Rudder CLI.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="prerequisites" data-heading="Prerequisites" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>&lt;ul>
&lt;li>Rudder CLI tool &lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/installation/#install-rudder-cli" >installed and authenticated&lt;/a> with your &lt;a href="https://www.rudderstack.com/docs/access-management/service-access-tokens/#workspace-sat" >workspace-level Service Access Token&lt;/a>&lt;/li>
&lt;li>A Rudder CLI project directory for storing the SQL model YAML resources&lt;/li>
&lt;li>&lt;strong>Important&lt;/strong>: At least one &lt;a href="https://www.rudderstack.com/docs/sources/reverse-etl/" >Reverse ETL source&lt;/a> in the RudderStack dashboard using the data warehouse you want to query — RudderStack uses the connection credentials used to set up the warehouse account this source to fetch the &lt;a href="#list-reverse-etl-accounts" >account ID&lt;/a>. An example is shown below:&lt;/li>
&lt;/ul>
&lt;figure class="image--main " >
&lt;a
data-lightbox="image-images/retl-sources/postgres-connection-credentials.webp" href="https://www.rudderstack.com/docs/docs/images/retl-sources/postgres-connection-credentials.webp"
>
&lt;img src="https://www.rudderstack.com/docs/docs/images/retl-sources/postgres-connection-credentials.webp"
alt="Connection credentials for PostgreSQL source"
decoding="async" loading="lazy" class="img-shortcode"/>
&lt;/a>
&lt;/figure>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="list-reverse-etl-accounts" data-heading="List Reverse ETL accounts" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="list-reverse-etl-accounts">List Reverse ETL accounts&lt;/h2>&lt;p>Before creating a SQL model resource, identify the account ID for the warehouse you want to connect to.&lt;/p>
&lt;p>Use the following command to list all accounts linked to your workspace:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli workspace accounts list
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This command displays all available accounts along with their IDs. Make note of the account ID that corresponds to your target warehouse — you will need this for the resource configuration.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="create-the-resource-file" data-heading="Create the resource file" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="create-the-resource-file">Create the resource file&lt;/h2>&lt;p>Create a new YAML file in your project folder containing the SQL model configuration. This file should have the following structure:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;rudder/v0.1&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;retl-source-sql-model&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;product-purchases-model&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;product-purchases-model&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">display_name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Product Purchases SQL Model&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">primary_key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;user_id&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">description&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;SQL model for product purchases&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">source_definition&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;postgres&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enabled&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">account_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2rzPI1ARibivIvNH5DSpAKGTATy&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">sql&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> SELECT
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> user_id,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> event_name,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> event_type,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timestamp,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> properties,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> pruduct_id
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> FROM
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> user_events
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> WHERE
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timestamp &amp;gt;= CURRENT_DATE() - INTERVAL 180 DAY
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> ORDER BY
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timestamp DESC&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>See the &lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/yaml-sql-models/" >SQL Model YAML reference&lt;/a> for more details on the parameters.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="sql-query-options" data-heading="SQL query options" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="sql-query-options">SQL query options&lt;/h2>&lt;p>RudderStack provides two options for defining your SQL query:&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="inline-sql" data-heading="Inline SQL" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h3 id="inline-sql">Inline SQL&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">sql&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> SELECT
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> user_id,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> event_name
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> FROM
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> user_events&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="external-file-reference" data-heading="External file reference" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h3 id="external-file-reference">External file reference&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">file&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;./queries/my-query.sql&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote class="warning">
&lt;div class="tip-quote">
&lt;img src=https://www.rudderstack.com/docs/docs/images/warning.svg alt="warning" loading="lazy" decoding="async" class="img__small" style="
margin-top: 3px; width: 20px;height: 16px;" />
&lt;div class="tip-text">You must use exactly one of &lt;code>sql&lt;/code> or &lt;code>file&lt;/code> — they are mutually exclusive.&lt;/div>
&lt;/div>
&lt;/blockquote>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="supported-sources" data-heading="Supported sources" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h3 id="supported-sources">Supported sources&lt;/h3>&lt;p>The &lt;code>source_definition&lt;/code> field in the &lt;code>spec&lt;/code> parameter supports the below warehouses:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Warehouse&lt;/th>
&lt;th style="text-align:left">&lt;code>source_definition&lt;/code> value&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">PostgreSQL&lt;/td>
&lt;td style="text-align:left">&lt;code>postgres&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">MySQL&lt;/td>
&lt;td style="text-align:left">&lt;code>mysql&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Snowflake&lt;/td>
&lt;td style="text-align:left">&lt;code>snowflake&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Redshift&lt;/td>
&lt;td style="text-align:left">&lt;code>redshift&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">BigQuery&lt;/td>
&lt;td style="text-align:left">&lt;code>bigquery&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Databricks&lt;/td>
&lt;td style="text-align:left">&lt;code>databricks&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Trino&lt;/td>
&lt;td style="text-align:left">&lt;code>trino&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="apply-the-sql-model" data-heading="Apply the SQL model" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="apply-the-sql-model">Apply the SQL model&lt;/h2>&lt;p>Once you have created the resource file, use the following commands to validate and create the SQL model:&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="validate-configuration" data-heading="Validate configuration" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h3 id="validate-configuration">Validate configuration&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli validate -l path/to/project
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="dry-run" data-heading="Dry run" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h3 id="dry-run">Dry run&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli apply -l path/to/project --dry-run
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The above command lists the changes that would be applied without actually making them.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="apply-changes" data-heading="Apply changes" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h3 id="apply-changes">Apply changes&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli apply -l path/to/project
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>After successful application, the SQL model will be created in your workspace and you can manage it through the CLI.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="update-the-sql-model" data-heading="Update the SQL model" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="update-the-sql-model">Update the SQL model&lt;/h2>&lt;p>You can modify any field in the YAML file of your existing SQL model — including &lt;code>source_definition&lt;/code>.&lt;/p>
&lt;blockquote class="warning">
&lt;div class="tip-quote">
&lt;img src=https://www.rudderstack.com/docs/docs/images/warning.svg alt="warning" loading="lazy" decoding="async" class="img__small" style="
margin-top: 3px; width: 20px;height: 16px;" />
&lt;div class="tip-text">Changing the &lt;code>id&lt;/code> field will delete the existing resource and create a new one.&lt;/div>
&lt;/div>
&lt;/blockquote>
&lt;p>To apply the updates, repeat the &lt;a href="#apply-the-sql-model" >validation and apply commands&lt;/a> listed above:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli validate -l path/to/project
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rudder-cli apply -l path/to/project --dry-run &lt;span class="c1"># Optional: Preview changes&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rudder-cli apply -l path/to/project
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="best-practices" data-heading="Best practices" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="best-practices">Best practices&lt;/h2>&lt;ul>
&lt;li>&lt;strong>Use external files&lt;/strong>: For complex queries, use the &lt;a href="#external-file-reference" >&lt;code>file&lt;/code> option&lt;/a> to keep your SQL in separate &lt;code>.sql&lt;/code> files for better syntax highlighting and version control.&lt;/li>
&lt;li>&lt;strong>Descriptive IDs&lt;/strong>: Choose clear, descriptive IDs that reflect the model&amp;rsquo;s purpose.&lt;/li>
&lt;li>&lt;strong>Test first&lt;/strong>: Always run the &lt;a href="#apply-the-sql-model" >validation and dry-run commands&lt;/a> before applying any changes.&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="next-steps" data-heading="Next steps" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" data-title="Create New SQL Model Resource using Rudder CLI" -->
&lt;h2 id="next-steps">Next steps&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models-walkthrough/" >End-to-End Walkthrough: SQL Models with Rudder CLI&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" >Import existing SQL model resources&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" >Validate and preview your SQL models&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/yaml-sql-models/" >YAML reference&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Archive: Import Existing SQL Model Resource using Rudder CLI</title><link>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/</guid><description>
&lt;p>This guide explains how to import existing SQL model resources from your workspace into your CLI project. This allows you to bring existing resources under version control and manage them through Git workflows.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="prerequisites" data-heading="Prerequisites" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>&lt;ul>
&lt;li>Rudder CLI tool &lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/installation/#install-rudder-cli" >installed and authenticated&lt;/a> with your access token&lt;/li>
&lt;li>A CLI project directory for storing the SQL model YAML resources&lt;/li>
&lt;li>Existing SQL model resources in your workspace&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="list-available-sql-model-resources" data-heading="List available SQL model resources" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="list-available-sql-model-resources">List available SQL model resources&lt;/h2>&lt;p>First, identify which SQL model resources are available in your workspace for import:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli workspace retl-sources list
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This command lists all SQL model resources in your workspace. Make note of the &lt;code>source_id&lt;/code> for the resource you want to import — you will need this in the next step.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="import-the-resource" data-heading="Import the resource" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="import-the-resource">Import the resource&lt;/h2>&lt;p>Use the &lt;code>import&lt;/code> command to bring an existing resource into your CLI project — this command creates a YAML file that describes the imported resource.&lt;/p>
&lt;p>RudderStack provides two ways to import an existing resource:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="#import-the-resource-with-inline-sql" >Import the resource with inline SQL&lt;/a>&lt;/li>
&lt;li>&lt;a href="#import-the-resource-with-an-external-sql-file" >Import the resource with an external SQL file&lt;/a>&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="import-the-resource-with-inline-sql" data-heading="Import the resource with inline SQL" data-level="4" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h4 id="import-the-resource-with-inline-sql">Import the resource with inline SQL&lt;/h4>&lt;p>To import the resource with inline SQL, use the &lt;code>import&lt;/code> command without the &lt;code>--sql-location&lt;/code> flag, as shown:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli import retl-sources --local-id api-test-10 --remote-id 2zMxxCKnGqkQLHffzCCIAvvxBso -l ./path/to/project
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>By default, the generated file will have the following format with inline SQL:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;rudder/v0.1&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;retl-source-sql-model&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">import&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">workspaces&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">workspace_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2dgUfFqnI6LFhlDmYPd8mA4Xrnc&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">local_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">remote_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2zMwvwOG8zYJoJRHdmtN2ka1VUY&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">account_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2rzPI1ARibivIvNH5DSpAKGTATy&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">description&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">display_name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enabled&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">primary_key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">source_definition&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;postgres&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">sql&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> SELECT
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> user_id,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> event_name,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timestamp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> FROM
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> user_events
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> WHERE
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timestamp &amp;gt;= CURRENT_DATE() - INTERVAL 30 DAY&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="import-the-resource-with-an-external-sql-file" data-heading="Import the resource with an external SQL file" data-level="4" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h4 id="import-the-resource-with-an-external-sql-file">Import the resource with an external SQL file&lt;/h4>&lt;p>To store the SQL query in a separate file while importing the resource, use the &lt;code>--sql-location&lt;/code> parameter, as shown:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli import retl-sources --local-id api-test-10 --remote-id 2zMxxCKnGqkQLHffzCCIAvvxBso -l ./path/to/project --sql-location ./sql/api-test-10.sql
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This command creates a YAML file that references the external SQL file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;rudder/v0.1&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;retl-source-sql-model&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">import&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">workspaces&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">workspace_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2dgUfFqnI6LFhlDmYPd8mA4Xrnc&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">local_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">remote_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2zMwvwOG8zYJoJRHdmtN2ka1VUY&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">account_id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2rzPI1ARibivIvNH5DSpAKGTATy&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">description&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">display_name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enabled&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">id&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;api-test-10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">primary_key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">source_definition&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;postgres&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">file&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;./sql/api-test-10.sql&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>See the &lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/yaml-sql-models/" >SQL Model YAML reference&lt;/a> for more details on the above parameters.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="important-considerations" data-heading="Important considerations" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h3 id="important-considerations">Important considerations&lt;/h3>&lt;ul>
&lt;li>The &lt;code>metadata.import&lt;/code> section tracks the relationship between your local CLI resource and the remote workspace resource. This enables the CLI to sync changes properly.&lt;/li>
&lt;li>By default, the SQL query is stored inline in the YAML file using the &lt;code>sql&lt;/code> field.&lt;/li>
&lt;li>If you use the &lt;code>--sql-location&lt;/code> parameter, the import process creates a separate &lt;code>.sql&lt;/code> file containing the SQL query and references it using the &lt;code>file&lt;/code> field.&lt;/li>
&lt;li>All current settings from your workspace resource are captured in the &lt;code>spec&lt;/code> section.&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="import-command-parameters" data-heading="Import command parameters" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="import-command-parameters">Import command parameters&lt;/h2>&lt;p>The following table lists the parameters for the &lt;code>import&lt;/code> command:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Parameter&lt;/th>
&lt;th style="text-align:left">Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">&lt;code>--local-id&lt;/code> &lt;br/> &lt;span style="color: #4D4DFF;font-size:12px;">Required&lt;/span>&lt;/td>
&lt;td style="text-align:left">The name you want to use for this resource in your CLI project&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>--remote-id&lt;/code> &lt;br/> &lt;span style="color: #4D4DFF;font-size:12px;">Required&lt;/span>&lt;/td>
&lt;td style="text-align:left">The source ID from your workspace obtained from the &lt;a href="#list-available-sql-model-resources" >list command&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>-l&lt;/code> or &lt;code>--location&lt;/code> &lt;br/> &lt;span style="color: #4D4DFF;font-size:12px;">Required&lt;/span>&lt;/td>
&lt;td style="text-align:left">Path to your project directory&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>--sql-location&lt;/code>&lt;/td>
&lt;td style="text-align:left">Path where you want to save the SQL query as an external file. If not provided, the SQL query will be stored inline in the YAML file&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="sync-the-imported-resource" data-heading="Sync the imported resource" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="sync-the-imported-resource">Sync the imported resource&lt;/h2>&lt;p>After generating the resource file, run the &lt;code>apply&lt;/code> command to complete the import process:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli validate -l path/to/project &lt;span class="c1"># Validate changes&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rudder-cli apply -l path/to/project --dry-run &lt;span class="c1"># Preview changes&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rudder-cli apply -l path/to/project &lt;span class="c1"># Apply changes&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>After successful application, the SQL model will be created in your workspace and you can manage it through the CLI.&lt;/p>
&lt;p>Once imported, you can modify any field in the YAML file. Changes are applied to the workspace resource when you run the &lt;code>apply&lt;/code> command.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="delete-resources" data-heading="Delete resources" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h3 id="delete-resources">Delete resources&lt;/h3>&lt;p>If you remove the YAML file from your project, the next &lt;code>apply&lt;/code> command will delete the SQL model from your workspace. Therefore, be cautious with this operation.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="troubleshooting" data-heading="Troubleshooting" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="troubleshooting">Troubleshooting&lt;/h2>&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Issue&lt;/th>
&lt;th style="text-align:left">Resolution steps&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">Import fails&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Verify the &lt;code>remote-id&lt;/code> exists and is accessible in your workspace&lt;/li>&lt;li>Ensure you have proper permissions to read the resource&lt;/li>&lt;li>Confirm that the &lt;code>local-id&lt;/code> does not conflict with existing resources&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Apply command fails after import&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Ensure the YAML file is present and properly formatted&lt;/li>&lt;li>If using the &lt;code>--sql-location&lt;/code> flag, ensure both the YAML file and the generated SQL file are present&lt;/li>&lt;li>Verify your CLI is authenticated and has access to the workspace&lt;/li>&lt;li>Confirm that no manual changes were made to the resource in the UI after import&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="best-practices" data-heading="Best practices" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="best-practices">Best practices&lt;/h2>&lt;ul>
&lt;li>&lt;strong>Consistent naming&lt;/strong>: Use descriptive &lt;code>local-id&lt;/code> values that reflect the resource&amp;rsquo;s purpose.&lt;/li>
&lt;li>&lt;strong>Immediate sync&lt;/strong>: Always run the apply command immediately after import to establish proper tracking.&lt;/li>
&lt;li>&lt;strong>Commit together&lt;/strong>: If using the &lt;code>--sql-location&lt;/code> flag, commit both the YAML and SQL files together to maintain consistency.&lt;/li>
&lt;li>&lt;strong>Environment planning&lt;/strong>: Consider how to handle different environments before importing multiple resources.&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="next-steps" data-heading="Next steps" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" data-title="Import Existing SQL Model Resource using Rudder CLI" -->
&lt;h2 id="next-steps">Next steps&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models-walkthrough/" >End-to-End Walkthrough: SQL Models with Rudder CLI&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" >Create new SQL model resources&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" >Validate and preview your SQL models&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/yaml-sql-models/" >YAML reference&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Archive: Validate SQL Model Resource using Rudder CLI</title><link>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/</guid><description>
&lt;p>This guide covers how to validate configurations and preview query results using Rudder CLI.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="prerequisites" data-heading="Prerequisites" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>&lt;ul>
&lt;li>Rudder CLI tool &lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/installation/#install-rudder-cli" >installed and authenticated&lt;/a> with your access token&lt;/li>
&lt;li>A CLI project directory with SQL model resources&lt;/li>
&lt;li>Access to the data warehouses referenced by your models&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="overview" data-heading="Overview" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="overview">Overview&lt;/h2>&lt;p>The Rudder CLI provides powerful validation and preview capabilities that help you test your SQL models before deploying them to production.&lt;/p>
&lt;p>The preview feature allows you to execute your SQL queries and see the results before applying changes to your workspace — this is helpful for testing query logic and ensuring data quality.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="preview-command" data-heading="Preview command" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="preview-command">Preview command&lt;/h2>&lt;p>Run the below command to preview a specific SQL model resource:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli retl-sources preview campaigns-cli -l path/to/project --limit &lt;span class="m">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>When you run a preview command, Rudder CLI:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Validates connection&lt;/strong>: Confirms it can connect to the specified data warehouse.&lt;/li>
&lt;li>&lt;strong>Executes query&lt;/strong>: Runs your SQL query against the warehouse.&lt;/li>
&lt;li>&lt;strong>Returns results&lt;/strong>: Shows you a sample of the query results.&lt;/li>
&lt;/ol>
&lt;blockquote class="success">
&lt;div class="tip-quote">
&lt;img src=https://www.rudderstack.com/docs/docs/images/tick.svg loading="lazy" alt="success" decoding="async" class="img__small" style="
margin-top: 3px; width: 20px;height: 16px;" />
&lt;div class="tip-text">
You can also use the &lt;code>preview&lt;/code> command to validate that the primary key column is present in the result set.
&lt;/div>
&lt;/div>
&lt;/blockquote>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="command-parameters" data-heading="Command parameters" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="command-parameters">Command parameters&lt;/h3>&lt;p>The following table lists the parameters for the preview command:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Parameter&lt;/th>
&lt;th style="text-align:left">Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">Resource ID&lt;/td>
&lt;td style="text-align:left">The first argument specifies which SQL model to preview — it uses the &lt;code>id&lt;/code> value from your YAML file&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>-l&lt;/code> or &lt;code>--location&lt;/code>&lt;/td>
&lt;td style="text-align:left">Path to your project directory&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>--limit&lt;/code>&lt;/td>
&lt;td style="text-align:left">Number of rows to fetch &lt;br />&lt;br />&lt;strong>Default value&lt;/strong>: 100 — RudderStack returns an error if this value is exceeded&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>-j&lt;/code> or &lt;code>--json&lt;/code>&lt;/td>
&lt;td style="text-align:left">Output results in JSON format instead of table format&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;code>--interactive&lt;/code>&lt;/td>
&lt;td style="text-align:left">Controls whether output should be in interactive mode &lt;br />&lt;br />&lt;strong>Default value&lt;/strong>: true&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="preview-command-examples" data-heading="Preview command examples" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="preview-command-examples">Preview command examples&lt;/h3>&lt;p>The following example demonstrates the key parameters available with the preview command:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli retl-sources preview api-test-10 --location path/to/project --limit &lt;span class="m">5&lt;/span> -j --interactive&lt;span class="o">=&lt;/span>&lt;span class="nb">false&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The above command:&lt;/p>
&lt;ul>
&lt;li>Previews the SQL model with ID &lt;code>api-test-10&lt;/code>&lt;/li>
&lt;li>Uses &lt;code>path/to/project&lt;/code> as the location for the CLI project directory&lt;/li>
&lt;li>Limits results to 5 rows using &lt;code>--limit 5&lt;/code>&lt;/li>
&lt;li>Outputs results in JSON format using &lt;code>-j&lt;/code>&lt;/li>
&lt;li>Runs in non-interactive mode using &lt;code>--interactive=false&lt;/code>&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="validation" data-heading="Validation" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="validation">Validation&lt;/h2>&lt;p>Validation ensures your SQL model configurations are correct before deployment. It performs comprehensive checks without executing the full query.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="validate-a-specific-resource" data-heading="Validate a specific resource" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="validate-a-specific-resource">Validate a specific resource&lt;/h3>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">rudder-cli retl-sources validate campaigns-cli -l path/to/project
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="what-validation-checks" data-heading="What validation checks" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="what-validation-checks">What validation checks&lt;/h3>&lt;p>The validation process verifies:&lt;/p>
&lt;p>&lt;strong>SQL Syntax&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Ensures your SQL query is syntactically correct&lt;/li>
&lt;li>Validates it&amp;rsquo;s compatible with your specified warehouse type&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Connectivity&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Tests connection to the specified account/warehouse&lt;/li>
&lt;li>Verifies authentication and permissions&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Configuration integrity&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Validates all required fields are present and properly formatted&lt;/li>
&lt;li>Ensures account ID references exist and are accessible&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Query execution (limited)&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Tests that the query can execute without errors&lt;/li>
&lt;li>May run a limited version of the query to validate structure&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="best-practices" data-heading="Best practices" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="best-practices">Best practices&lt;/h2>&lt;p>This section provides best practices for using validation and preview in your development and CI/CD workflows.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="development-workflow" data-heading="Development workflow" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="development-workflow">Development workflow&lt;/h3>&lt;ul>
&lt;li>&lt;strong>Write query&lt;/strong>: Create or modify your SQL in the YAML or SQL file.&lt;/li>
&lt;li>&lt;strong>Validate first&lt;/strong>: Run validation to check syntax and configuration.&lt;/li>
&lt;li>&lt;strong>Dry run&lt;/strong>: Use &lt;code>--dry-run&lt;/code> with &lt;code>apply&lt;/code> commands to see what will change.&lt;/li>
&lt;li>&lt;strong>Preview results&lt;/strong>: Use preview to verify query logic and results.&lt;/li>
&lt;li>&lt;strong>Iterate&lt;/strong>: Refine your query based on preview results.&lt;/li>
&lt;li>&lt;strong>Final validation&lt;/strong>: Run validation once more before committing.&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="cicd-pipeline" data-heading="CI/CD pipeline" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="cicd-pipeline">CI/CD pipeline&lt;/h3>&lt;ul>
&lt;li>&lt;strong>Always validate&lt;/strong>: Include validation in your automated checks.&lt;/li>
&lt;li>&lt;strong>Limited preview&lt;/strong>: Use preview sparingly in CI/CD due to performance implications.&lt;/li>
&lt;/ul>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="troubleshooting" data-heading="Troubleshooting" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="troubleshooting">Troubleshooting&lt;/h2>&lt;p>This section provides troubleshooting tips for common issues you may encounter when using validation and preview.&lt;/p>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="common-validation-errors" data-heading="Common validation errors" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="common-validation-errors">Common validation errors&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Issue&lt;/th>
&lt;th style="text-align:left">Resolution steps&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">Account not found&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Verify the &lt;code>account_id&lt;/code> exists in your workspace&lt;/li>&lt;li>Check your CLI is authenticated with the correct workspace&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">SQL Syntax Error&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Review your query syntax for the specific warehouse type&lt;/li>&lt;li>Test the query directly in your warehouse&amp;rsquo;s query interface&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Primary Key Column Missing&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Ensure your query returns a column with the name specified in &lt;code>primary_key&lt;/code>&lt;/li>&lt;li>Check for typos in column names&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Connection Timeout&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Verify network connectivity to your warehouse&lt;/li>&lt;li>Check if warehouse credentials need renewal&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="error-handling" data-heading="Error handling" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="error-handling">Error handling&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Error&lt;/th>
&lt;th style="text-align:left">Resolution steps&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">Connection issues&lt;/td>
&lt;td style="text-align:left">Check account credentials and network connectivity&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">SQL errors&lt;/td>
&lt;td style="text-align:left">Review query syntax and warehouse-specific SQL dialect requirements&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Primary key issues&lt;/td>
&lt;td style="text-align:left">Ensure the specified primary key column exists in your query results&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Timeout issues&lt;/td>
&lt;td style="text-align:left">Simplify complex queries for validation, optimize for production&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="performance-considerations" data-heading="Performance considerations" data-level="3" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h3 id="performance-considerations">Performance considerations&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">Issue&lt;/th>
&lt;th style="text-align:left">Resolution steps&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">Large result sets&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Use smaller &lt;code>--limit&lt;/code> values for initial testing&lt;/li>&lt;li>Consider adding &lt;code>WHERE&lt;/code> clauses to reduce data volume during development&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Complex queries&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Break down complex queries into simpler parts for testing&lt;/li>&lt;li>Use preview to validate intermediate steps&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">Resource usage&lt;/td>
&lt;td style="text-align:left">&lt;ul>&lt;li>Preview commands consume warehouse compute resources&lt;/li>&lt;li>Be mindful of costs when running against production warehouses&lt;/li>&lt;/ul>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;!-- end-chunk -->
&lt;!-- begin-chunk data-anchor="see-also" data-heading="See also" data-level="2" data-permalink="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/validate/" data-title="Validate SQL Model Resource using Rudder CLI" -->
&lt;h2 id="see-also">See also&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models-walkthrough/" >End-to-End Walkthrough: SQL Models with Rudder CLI&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/create/" >Create New SQL Model Resources&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/sql-models/import/" >Import Existing SQL Model Resources&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rudderstack.com/docs/archive/rudder-cli/v0.1/yaml-sql-models/" >SQL Model Resources YAML Reference&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>