<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Parametrizing queries in DAB deployments in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152090#M53758</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Hi Ashwin, this approach wouldn't work for me due to the apostrophe injected. Sorry for the bad formatting, I am running into errors trying to send it properly.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;- task_key: example &lt;BR /&gt;sql_task: &lt;BR /&gt;file: &lt;BR /&gt;path: query.sql &lt;BR /&gt;source: WORKSPACE &lt;BR /&gt;warehouse_id: abc &lt;BR /&gt;parameters: &lt;BR /&gt;    catalog: data_catalog_${var.environment}&lt;BR /&gt;    schema: source_schema &lt;BR /&gt;    table: mat_view&lt;/PRE&gt;&lt;PRE&gt;CREATE MATERIALIZED VIEW IF NOT EXISTS {{catalog}}.{{schema}}.{{table}}​&lt;/PRE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;[PARSE_SYNTAX_ERROR] Syntax error&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;CREATE MATERIALIZED VIEW IF NOT EXISTS&lt;BR /&gt;'data_catalog_PROD'.'source_schema'.'mat_view'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 26 Mar 2026 04:49:15 GMT</pubDate>
    <dc:creator>malterializedvw</dc:creator>
    <dc:date>2026-03-26T04:49:15Z</dc:date>
    <item>
      <title>Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/151106#M53583</link>
      <description>&lt;P&gt;Hi folks,&lt;BR /&gt;I would like to ask for best practises concerning the topic of parametrizing queries in Databricks Asset Bundle deployments.This topic is relevant to differentiate between deployments on different environments as well as [dev]-deployments vs. production deployments.&lt;BR /&gt;A well working example are notebook tasks or DLT jobs: I can pass all sorts of parameters. I can not only parametrize the environment (dev/test/prod) but also database objects (e.g. tables) with an identifier for [dev]-deployments (to not interfere with the regular database objects).&lt;BR /&gt;The problem now arises with Mat Views. For those I must use a SQL warehouse, so I cant use the existing tricks. Neither can I use a (parametrizable) Databricks Query object, as those are not commitable into repos. I am currently using a sql_task on a flat file which contains a hard coded query (s. below).&lt;BR /&gt;Using the power of sed in the deployment process, I am indeed able to handle the environment. But [dev] deployments are not handled by that and I secretly hope for a better solution than using sed.&lt;BR /&gt;Is there?&lt;BR /&gt;Thanks and best regards&lt;BR /&gt;```&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;task_key&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;task_example&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sql_task&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;file&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;path&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;/Workspace/${var.path}/files/query.sql&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;source&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WORKSPACE&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;warehouse_id&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;abc123&lt;BR /&gt;```&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Mar 2026 04:22:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/151106#M53583</guid>
      <dc:creator>malterializedvw</dc:creator>
      <dc:date>2026-03-17T04:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/151127#M53588</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/219179"&gt;@malterializedvw&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;You don’t need Databricks Query objects for this. Have you considered using&amp;nbsp;bundle variables + SQL task parameters on the .sql file? Check this &lt;A href="https://docs.databricks.com/aws/en/dev-tools/bundles/job-task-types#sql-task" target="_self"&gt;documentation.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The good thing is that&amp;nbsp;sql_task supports a parameters map. Any key you define there can be referenced in your SQL file as {{parameter_key}} and will be substituted by Databricks at run time.&lt;/P&gt;
&lt;P&gt;As an example, you do something like this in your query.sql..&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;CREATE OR REPLACE MATERIALIZED VIEW
  {{catalog}}.{{schema}}.orders_mv{{table_suffix}}
AS
SELECT *
FROM {{catalog}}.{{schema}}.orders{{table_suffix}};&lt;/LI-CODE&gt;
&lt;P&gt;That way, you can use the same sql in multiple environments without havng to use sed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Environment differences can handled via targets + variable overrides.&lt;/P&gt;
&lt;P&gt;Does this help?&lt;/P&gt;
&lt;P class="p1"&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG&gt;&lt;I&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2026 10:19:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/151127#M53588</guid>
      <dc:creator>Ashwin_DSA</dc:creator>
      <dc:date>2026-03-17T10:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/151128#M53589</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Not sure if I understand correctly, but the issue is that you are using .sql file that have hardcoded env?&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Use bundle substitutions/variables inside the SQL file itself&lt;/P&gt;&lt;P&gt;Databricks Asset Bundles support variable substitution not only in YAML but also in SQL files referenced by tasks, via the same {{var.name}} syntax. The pattern:&lt;BR /&gt;databricks.yml:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;bundle:
  name: my-bundle

variables:
  env:
    default: dev
  table_suffix:
    default: _dev

targets:
  dev:
    default: true
    variables:
      env: dev
      table_suffix: _dev
  prod:
    variables:
      env: prod
      table_suffix: ""&lt;/LI-CODE&gt;&lt;P&gt;SQL:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE MATERIALIZED VIEW IDENTIFIER(
  :env || '_gold.schema_name.mv_name'
) AS
SELECT *
FROM IDENTIFIER(
  :env || '_silver.schema_name.src_table_name'
);&lt;/LI-CODE&gt;&lt;P&gt;job.yml:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;resources:
  jobs:
    mv-job:
      name: mv-job
      tasks:
        - task_key: mv_task
          sql_task:
            file:
              path: ./sql/mv_example.sql   # committed in repo
              source: WORKSPACE
            warehouse_id: abc123
            parameters:
              env: dev&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 17 Mar 2026 10:35:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/151128#M53589</guid>
      <dc:creator>Pat</dc:creator>
      <dc:date>2026-03-17T10:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152090#M53758</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Hi Ashwin, this approach wouldn't work for me due to the apostrophe injected. Sorry for the bad formatting, I am running into errors trying to send it properly.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;- task_key: example &lt;BR /&gt;sql_task: &lt;BR /&gt;file: &lt;BR /&gt;path: query.sql &lt;BR /&gt;source: WORKSPACE &lt;BR /&gt;warehouse_id: abc &lt;BR /&gt;parameters: &lt;BR /&gt;    catalog: data_catalog_${var.environment}&lt;BR /&gt;    schema: source_schema &lt;BR /&gt;    table: mat_view&lt;/PRE&gt;&lt;PRE&gt;CREATE MATERIALIZED VIEW IF NOT EXISTS {{catalog}}.{{schema}}.{{table}}​&lt;/PRE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;[PARSE_SYNTAX_ERROR] Syntax error&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;CREATE MATERIALIZED VIEW IF NOT EXISTS&lt;BR /&gt;'data_catalog_PROD'.'source_schema'.'mat_view'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 26 Mar 2026 04:49:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152090#M53758</guid>
      <dc:creator>malterializedvw</dc:creator>
      <dc:date>2026-03-26T04:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152094#M53759</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/59366"&gt;@Pat&lt;/a&gt;&amp;nbsp;, thanks for the answer, I didnt know about the IDENTIFIER-clause and it makes me hopeful.&lt;BR /&gt;Yes, you got me right. So, I tried to apply your suggestion to my problem, defining &lt;EM&gt;catalog&lt;/EM&gt;, &lt;EM&gt;schema&lt;/EM&gt; and &lt;EM&gt;table&lt;/EM&gt; in the job.yml and then updating my &lt;EM&gt;query.sql&lt;/EM&gt;&amp;nbsp;as follows:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;CREATE&lt;/SPAN&gt;&lt;SPAN&gt; MATERIALIZED VIEW &lt;/SPAN&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt; &lt;SPAN&gt;NOT&lt;/SPAN&gt; &lt;SPAN&gt;EXISTS&lt;/SPAN&gt;&lt;SPAN&gt; IDENTIFIER(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; :catalog &lt;/SPAN&gt;&lt;SPAN&gt;||&lt;/SPAN&gt;&lt;SPAN&gt; :schema &lt;/SPAN&gt;&lt;SPAN&gt;||&lt;/SPAN&gt;&lt;SPAN&gt; :table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Also I tried this:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;:catalog &lt;/SPAN&gt;&lt;SPAN&gt;||&lt;/SPAN&gt; &lt;SPAN&gt;'.'&lt;/SPAN&gt; &lt;SPAN&gt;||&lt;/SPAN&gt;&lt;SPAN&gt; :schema &lt;/SPAN&gt;&lt;SPAN&gt;||&lt;/SPAN&gt; &lt;SPAN&gt;'.'&lt;/SPAN&gt; &lt;SPAN&gt;||&lt;/SPAN&gt;&lt;SPAN&gt; :table&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Neither worked though.&lt;BR /&gt;&lt;EM&gt;&lt;SPAN class=""&gt;Exactly one CREATE [ LIVE TABLE | MATERIALIZED VIEW | STREAMING TABLE ] statement expected, but 0 found&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 05:17:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152094#M53759</guid>
      <dc:creator>malterializedvw</dc:creator>
      <dc:date>2026-03-26T05:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152175#M53779</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/219179"&gt;@malterializedvw&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Try this... Build your .sql file like the below,&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;CREATE MATERIALIZED VIEW IF NOT EXISTS
  IDENTIFIER('{{catalog}}.{{schema}}.{{table}}')
AS
SELECT
  ...
FROM
  ...;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG&gt;&lt;I&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2026 13:34:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152175#M53779</guid>
      <dc:creator>Ashwin_DSA</dc:creator>
      <dc:date>2026-03-26T13:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152257#M53795</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/216690"&gt;@Ashwin_DSA&lt;/a&gt;&amp;nbsp;&amp;nbsp;, this does not work either.&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;[PARSE_SYNTAX_ERROR] Syntax error at or near 'catalog'. SQLSTATE: 42601 (line 1, pos 52) == SQL == CREATE MATERIALIZED VIEW IF NOT EXISTS IDENTIFIER(''catalog.schema.table'') &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2026 08:49:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152257#M53795</guid>
      <dc:creator>malterializedvw</dc:creator>
      <dc:date>2026-03-27T08:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152263#M53796</link>
      <description>&lt;P&gt;The best I could come up if after some back and forth with Claude is this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;DECLARE target_fqn STRING;
DECLARE source_fqn STRING;
DECLARE q STRING;
DECLARE sql_stmt STRING;
SET VAR target_fqn = :target_fqn;
SET VAR source_fqn = :source_fqn;
SET VAR q = char(39);
SET VAR sql_stmt = CONCAT(
  'CREATE MATERIALIZED VIEW IF NOT EXISTS ', target_fqn,
  ' TBLPROPERTIES (', q, 'delta.columnMapping.mode', q, ' = ', q, 'name', q, ')',
  ' TRIGGER ON UPDATE',
  ' AS',
  ' select',
  '   cast(abc as TIMESTAMP) as `A B C`,',
  '   cast(xyz as TIMESTAMP) as `X Y Z`,',

  ' from ', source_fqn
);
EXECUTE IMMEDIATE sql_stmt&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;There must be a better way in Databricks?&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2026 09:00:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152263#M53796</guid>
      <dc:creator>malterializedvw</dc:creator>
      <dc:date>2026-03-27T09:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Parametrizing queries in DAB deployments</title>
      <link>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152284#M53804</link>
      <description>&lt;P&gt;Hm, the IDENTIFIER({{var}} || string) should work for create statements with DAB.&lt;BR /&gt;I also spent way too much time on AI giving me wrong answers (Jinja templating format on the first place).&lt;BR /&gt;Mind that there are no spaces in {{var}}.&lt;/P&gt;&lt;P&gt;BUT there are some limitations, f.e. in defining FKs f.e. (REFERENCES). That does not work (yet).&lt;BR /&gt;Dunno if this helps&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2026 10:04:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/parametrizing-queries-in-dab-deployments/m-p/152284#M53804</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2026-03-27T10:04:31Z</dc:date>
    </item>
  </channel>
</rss>

