<?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 Using Parameters in EXECUTE IMMEDIATE on Databricks SQL 2025.15 not working in Warehousing &amp; Analytics</title>
    <link>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115289#M2005</link>
    <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV class=""&gt;We are having an issue using parameters with&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;EXECUTE IMMEDIATE&lt;SPAN&gt;&amp;nbsp;statements, when running on SQL serverless running DBSQL v2025.15 (currently in preview channel):&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;declare or replace var query = "SELECT :PARAMETER_1";
EXECUTE IMMEDIATE query;&lt;BR /&gt;[&lt;SPAN&gt;&lt;A class="" title="https://docs.microsoft.com/azure/databricks/error-messages/error-classes#unbound_sql_parameter" href="https://docs.microsoft.com/azure/databricks/error-messages/error-classes#unbound_sql_parameter" target="_blank" rel="noopener"&gt;UNBOUND_SQL_PARAMETER] Found the unbound parameter: PARAMETER_1. Please, fix `args` and provide a mapping of the parameter to either a SQL literal or collection constructor functions such as `map()`, `array()`, `struct()`. SQLSTATE: 42P02; line 2, pos 7&lt;/A&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;See below for screenshots of issue. There's a workaround for v2025.15, to use ${PARAMETER_1} marker syntax but that is being deprecated in the future.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iamgoce_0-1744379589689.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15938iB5A122A9EBE7EFEB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iamgoce_0-1744379589689.png" alt="iamgoce_0-1744379589689.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iamgoce_0-1744379939492.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15941i5CDE5104F6C824CD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iamgoce_0-1744379939492.png" alt="iamgoce_0-1744379939492.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 11 Apr 2025 13:59:20 GMT</pubDate>
    <dc:creator>iamgoce</dc:creator>
    <dc:date>2025-04-11T13:59:20Z</dc:date>
    <item>
      <title>Using Parameters in EXECUTE IMMEDIATE on Databricks SQL 2025.15 not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115289#M2005</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV class=""&gt;We are having an issue using parameters with&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;EXECUTE IMMEDIATE&lt;SPAN&gt;&amp;nbsp;statements, when running on SQL serverless running DBSQL v2025.15 (currently in preview channel):&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;declare or replace var query = "SELECT :PARAMETER_1";
EXECUTE IMMEDIATE query;&lt;BR /&gt;[&lt;SPAN&gt;&lt;A class="" title="https://docs.microsoft.com/azure/databricks/error-messages/error-classes#unbound_sql_parameter" href="https://docs.microsoft.com/azure/databricks/error-messages/error-classes#unbound_sql_parameter" target="_blank" rel="noopener"&gt;UNBOUND_SQL_PARAMETER] Found the unbound parameter: PARAMETER_1. Please, fix `args` and provide a mapping of the parameter to either a SQL literal or collection constructor functions such as `map()`, `array()`, `struct()`. SQLSTATE: 42P02; line 2, pos 7&lt;/A&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;See below for screenshots of issue. There's a workaround for v2025.15, to use ${PARAMETER_1} marker syntax but that is being deprecated in the future.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iamgoce_0-1744379589689.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15938iB5A122A9EBE7EFEB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iamgoce_0-1744379589689.png" alt="iamgoce_0-1744379589689.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iamgoce_0-1744379939492.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15941i5CDE5104F6C824CD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iamgoce_0-1744379939492.png" alt="iamgoce_0-1744379939492.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Apr 2025 13:59:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115289#M2005</guid>
      <dc:creator>iamgoce</dc:creator>
      <dc:date>2025-04-11T13:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Parameters in EXECUTE IMMEDIATE on Databricks SQL 2025.15 not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115294#M2006</link>
      <description>&lt;DIV class="paragraph"&gt;Try this&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;The SQL script snippet provided (&lt;CODE&gt;DECLARE OR REPLACE var query = "SELECT :PARAMETER_1"; EXECUTE IMMEDIATE query;&lt;/CODE&gt;) will not work as intended in Databricks SQL because it uses a placeholder &lt;CODE&gt;:PARAMETER_1&lt;/CODE&gt; without properly assigning a value to it or using a parameterized query format compatible with Databricks SQL.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;The error most likely corresponds to &lt;STRONG&gt;unbound SQL parameters&lt;/STRONG&gt;, meaning the declared parameter (&lt;CODE&gt;:PARAMETER_1&lt;/CODE&gt;) is not bound to a concrete value at execution time. Also, Databricks SQL doesn't support bound parameter syntax like PostgreSQL or Oracle.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;To address this issue, you should:&lt;/DIV&gt;
&lt;OL start="1"&gt;
&lt;LI&gt;Directly substitute the desired value into the query string rather than using unbound parameters.&lt;/LI&gt;
&lt;LI&gt;Avoid usage of &lt;CODE&gt;EXECUTE IMMEDIATE&lt;/CODE&gt; unless required in a procedural-like SQL flow. Typically, you would write queries in standard SQL directly.&lt;/LI&gt;
&lt;/OL&gt;
&lt;DIV class="paragraph"&gt;Here is a working structure for SQL in Databricks for a valid query:&lt;/DIV&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-sql"&gt;DECLARE my_param STRING;
SET my_param = 'desired_value';
SELECT ${my_param};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="paragraph"&gt;This approach ensures that the value is dynamically assigned and incorporated into the SQL query.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;The error documentation from Azure Databricks confirms the need for properly binding or removing unbound parameters in SQL queries.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;Cheers, Louis.&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Apr 2025 14:24:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115294#M2006</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2025-04-11T14:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using Parameters in EXECUTE IMMEDIATE on Databricks SQL 2025.15 not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115299#M2007</link>
      <description>&lt;P&gt;Hi Louis,&lt;/P&gt;&lt;P&gt;Thanks for your reply and explanation.&lt;/P&gt;&lt;P&gt;Note that we do assign the parameter a value when executing the script inside a workflow job. In the sample notebook I also defined the parameter using the widget and assigned it a value directly.&lt;/P&gt;&lt;P&gt;I'm trying to then understand why the following code works in v2025.15:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;declare or replace var query = "SELECT '${PARAMETER_1}'";
EXECUTE IMMEDIATE query;&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iamgoce_0-1744382255282.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15944i78B7AFFB35AE3151/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iamgoce_0-1744382255282.png" alt="iamgoce_0-1744382255282.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Isn't ${PARAMETER_1} also unbound and should throw the same error?&lt;/P&gt;&lt;P&gt;And using :PARAMETER_1 is working fine in v2025.10. Was that an unintended behaviour and we should stay away from using it this way?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 14:42:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115299#M2007</guid>
      <dc:creator>iamgoce</dc:creator>
      <dc:date>2025-04-11T14:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Parameters in EXECUTE IMMEDIATE on Databricks SQL 2025.15 not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115309#M2008</link>
      <description>&lt;P&gt;Did a little more digging and have further information that might be helpful:&lt;/P&gt;
&lt;P&gt;The behavior you're observing with `${PARAMETER_1}` and `:PARAMETER_1` in Databricks SQL is tied to differences in how Databricks Runtime versions handle parameterization and syntax. Here's a detailed explanation:&lt;/P&gt;
&lt;P&gt;Why `${PARAMETER_1}` Works in v2025.15&lt;BR /&gt;1. String Interpolation Behavior: The `${PARAMETER_1}` syntax is interpreted as a string interpolation mechanism, where the value of the parameter (defined via a widget or variable in the notebook) is substituted directly into the query string before execution. This approach doesn't rely on formal parameter binding but instead performs a textual substitution at runtime.&lt;BR /&gt;2. Backward Compatibility: Databricks has historically supported `${}` syntax for parameter substitution, especially in notebooks. This syntax is less strict than named parameter markers (`:PARAMETER_1`) and doesn't require explicit binding via APIs or widgets, making it more user-friendly for interactive workflows.&lt;BR /&gt;3. Execution Context: In your example:&lt;BR /&gt;```sql&lt;BR /&gt;declare or replace var query = "SELECT '${PARAMETER_1}'";&lt;BR /&gt;EXECUTE IMMEDIATE query;&lt;BR /&gt;```&lt;BR /&gt;The value of `${PARAMETER_1}` is substituted into the query string before `EXECUTE IMMEDIATE` runs it, avoiding unbound parameter errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why `:PARAMETER_1` Worked in v2025.10&lt;BR /&gt;1. **Named Parameter Marker Syntax**: The `:PARAMETER_1` syntax represents a named parameter marker that requires explicit binding of a value before execution. In earlier versions like v2025.10, this behavior might have been supported implicitly in certain contexts (e.g., workflows or API calls) where the parameter was automatically bound to a widget or variable.&lt;BR /&gt;2. Potential Unintended Behavior: If `:PARAMETER_1` worked without explicit binding, it could have been due to leniency or an oversight in the runtime's implementation rather than a deliberate feature. Such behavior might not be consistent across all scenarios or runtime versions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Changes Between v2025.10 and v2025.15&lt;BR /&gt;1. Stricter Enforcement of Parameter Binding: Starting with newer Databricks Runtime versions (e.g., v2025.15), there has been a shift toward stricter enforcement of named parameter marker syntax (`:PARAMETER_1`). This aligns with best practices for SQL injection prevention and formal parameterization.&lt;BR /&gt;2. Deprecation of Implicit Binding: If `:PARAMETER_1` worked without explicit binding in v2025.10, this was likely unintended and has since been addressed to require proper mapping of parameters to values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should You Avoid Using `:PARAMETER_1`?&lt;BR /&gt;Yes, you should avoid relying on `:PARAMETER_1` without explicit binding because:&lt;BR /&gt;- It may not work consistently across different runtime versions or contexts (e.g., workflows vs. interactive notebooks).&lt;BR /&gt;- Databricks documentation strongly recommends using named parameter markers only when explicitly bound via APIs, widgets, or other mechanisms.&lt;BR /&gt;- The `${}` syntax remains more reliable for interactive workflows where direct substitution is sufficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Practices Moving Forward&lt;BR /&gt;To ensure compatibility and avoid runtime errors:&lt;BR /&gt;- Use `${PARAMETER}` for simple string interpolation in notebooks and workflows where values are defined via widgets or variables.&lt;BR /&gt;- Use `:PARAMETER_NAME` only when explicitly binding parameters through APIs or structured workflows.&lt;BR /&gt;- Always test queries on the target Databricks Runtime version to confirm expected behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 16:19:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115309#M2008</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2025-04-11T16:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using Parameters in EXECUTE IMMEDIATE on Databricks SQL 2025.15 not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115311#M2009</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/34815"&gt;@Louis_Frolio&lt;/a&gt;&amp;nbsp;thanks for the detailed explanation, that makes more sense.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 17:07:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/using-parameters-in-execute-immediate-on-databricks-sql-2025-15/m-p/115311#M2009</guid>
      <dc:creator>iamgoce</dc:creator>
      <dc:date>2025-04-11T17:07:47Z</dc:date>
    </item>
  </channel>
</rss>

