<?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: Use of Python variable in SQL cell in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126755#M47764</link>
    <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/130061"&gt;@jar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a frustrating situation where Databricks is deprecating the ${} syntax but the replacement :param syntax doesn't work in all contexts, particularly with CREATE VIEW statements.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. String Formatting/Templating&lt;/STRONG&gt;&lt;BR /&gt;Use Python string formatting to build your SQL dynamically:&lt;/P&gt;&lt;P&gt;# Python cell&lt;BR /&gt;table_name = "my_table"&lt;BR /&gt;filter_value = "some_value"&lt;/P&gt;&lt;P&gt;sql_query = f"""&lt;BR /&gt;CREATE OR REPLACE TEMPORARY VIEW my_view AS&lt;BR /&gt;SELECT * FROM {table_name}&lt;BR /&gt;WHERE column = '{filter_value}'&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;spark.sql(sql_query)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;2. Use Databricks Widgets with String Formatting&lt;/STRONG&gt;&lt;BR /&gt;If using widgets:&lt;/P&gt;&lt;P&gt;# Python cell&lt;BR /&gt;dbutils.widgets.text("param_name", "default_value")&lt;BR /&gt;param_value = dbutils.widgets.get("param_name")&lt;/P&gt;&lt;P&gt;create_view_sql = f"""&lt;BR /&gt;CREATE OR REPLACE TEMPORARY VIEW my_view AS&lt;BR /&gt;SELECT * FROM table&lt;BR /&gt;WHERE column = '{param_value}'&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;spark.sql(create_view_sql)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jul 2025 05:27:12 GMT</pubDate>
    <dc:creator>lingareddy_Alva</dc:creator>
    <dc:date>2025-07-29T05:27:12Z</dc:date>
    <item>
      <title>Use of Python variable in SQL cell</title>
      <link>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126752#M47763</link>
      <description>&lt;P&gt;If using spark.conf.set(&amp;lt;variable_name&amp;gt;, &amp;lt;variable_value&amp;gt;), or just referring a widget value directly, in a Python cell and then referring to it in a SQL cell with ${variable_name} one gets the warning: "S&lt;SPAN&gt;QL query contains a dollar sign parameter, $param, which is deprecated. Please migrate to the parameter marker syntax, :param." &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If one does so in a cell which creates a temporary view one gets the error "[&lt;A class="" href="https://docs.microsoft.com/azure/databricks/error-messages/unsupported-feature-error-class#parameter_marker_in_unexpected_statement" target="_blank" rel="noopener noreferrer"&gt;UNSUPPORTED_FEATURE.PARAMETER_MARKER_IN_UNEXPECTED_STATEMENT&lt;/A&gt;] The feature is not supported: Parameter markers are not allowed in the query of CREATE VIEW. SQLSTATE: 0A000". &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm using a &amp;gt; 15.2 runtime cluster.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;So, what does one do?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 01:51:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126752#M47763</guid>
      <dc:creator>jar</dc:creator>
      <dc:date>2025-07-29T01:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use of Python variable in SQL cell</title>
      <link>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126755#M47764</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/130061"&gt;@jar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a frustrating situation where Databricks is deprecating the ${} syntax but the replacement :param syntax doesn't work in all contexts, particularly with CREATE VIEW statements.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. String Formatting/Templating&lt;/STRONG&gt;&lt;BR /&gt;Use Python string formatting to build your SQL dynamically:&lt;/P&gt;&lt;P&gt;# Python cell&lt;BR /&gt;table_name = "my_table"&lt;BR /&gt;filter_value = "some_value"&lt;/P&gt;&lt;P&gt;sql_query = f"""&lt;BR /&gt;CREATE OR REPLACE TEMPORARY VIEW my_view AS&lt;BR /&gt;SELECT * FROM {table_name}&lt;BR /&gt;WHERE column = '{filter_value}'&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;spark.sql(sql_query)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;2. Use Databricks Widgets with String Formatting&lt;/STRONG&gt;&lt;BR /&gt;If using widgets:&lt;/P&gt;&lt;P&gt;# Python cell&lt;BR /&gt;dbutils.widgets.text("param_name", "default_value")&lt;BR /&gt;param_value = dbutils.widgets.get("param_name")&lt;/P&gt;&lt;P&gt;create_view_sql = f"""&lt;BR /&gt;CREATE OR REPLACE TEMPORARY VIEW my_view AS&lt;BR /&gt;SELECT * FROM table&lt;BR /&gt;WHERE column = '{param_value}'&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;spark.sql(create_view_sql)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 05:27:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126755#M47764</guid>
      <dc:creator>lingareddy_Alva</dc:creator>
      <dc:date>2025-07-29T05:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use of Python variable in SQL cell</title>
      <link>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126757#M47765</link>
      <description>&lt;P&gt;Frustrating indeed. Thank you,&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/24053"&gt;@lingareddy_Alva&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 05:40:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/use-of-python-variable-in-sql-cell/m-p/126757#M47765</guid>
      <dc:creator>jar</dc:creator>
      <dc:date>2025-07-29T05:40:18Z</dc:date>
    </item>
  </channel>
</rss>

