<?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 Create a table name without back tick when using set variable in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72085#M34492</link>
    <description>&lt;P&gt;When i tried to create a table name with variable like this&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;-- Set a string variable&lt;/SPAN&gt;&lt;BR /&gt;SET table_suffix = &lt;SPAN&gt;'suffix'&lt;/SPAN&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-- Use dynamic SQL to create a table with the variable as a suffix in the table name&lt;/SPAN&gt;&lt;BR /&gt;CREATE TABLE IF NOT EXISTS &amp;lt;dbname&amp;gt;.&lt;SPAN&gt;my_table_&lt;/SPAN&gt;${table_suffix} (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; id INT,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; name STRING,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; age INT&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;I could able to fetch the data from this table like this.&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;select * from gmi_im.my_table_&lt;SPAN&gt;`suffix`&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But I need it without back ticks . Is there any po way?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 07 Jun 2024 18:01:08 GMT</pubDate>
    <dc:creator>akshayauser</dc:creator>
    <dc:date>2024-06-07T18:01:08Z</dc:date>
    <item>
      <title>Create a table name without back tick when using set variable</title>
      <link>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72085#M34492</link>
      <description>&lt;P&gt;When i tried to create a table name with variable like this&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;-- Set a string variable&lt;/SPAN&gt;&lt;BR /&gt;SET table_suffix = &lt;SPAN&gt;'suffix'&lt;/SPAN&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-- Use dynamic SQL to create a table with the variable as a suffix in the table name&lt;/SPAN&gt;&lt;BR /&gt;CREATE TABLE IF NOT EXISTS &amp;lt;dbname&amp;gt;.&lt;SPAN&gt;my_table_&lt;/SPAN&gt;${table_suffix} (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; id INT,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; name STRING,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; age INT&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;I could able to fetch the data from this table like this.&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;select * from gmi_im.my_table_&lt;SPAN&gt;`suffix`&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But I need it without back ticks . Is there any po way?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Jun 2024 18:01:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72085#M34492</guid>
      <dc:creator>akshayauser</dc:creator>
      <dc:date>2024-06-07T18:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table name without back tick when using set variable</title>
      <link>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72129#M34501</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not that familiar with SQL variables. I can use them in queries, but can't seem to get the DDL to use them.&lt;BR /&gt;&lt;BR /&gt;What you are trying to do is simpler in python. See below for an example.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;table_suffix = 'suffix';

spark.sql(f"""
            CREATE TABLE IF NOT EXISTS shawn.default.table_with_{table_suffix} (
            id INT,
            name STRING,
            age INT
        )
        """ )

spark.sql(f"""
            INSERT INTO shawn.default.table_with_{table_suffix}
            VALUES
            (1, 'Batman', 30),
            (2, 'Robin', 20)
        """ )

df = spark.read.table(f"shawn.default.table_with_{table_suffix}")

display(df)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 08 Jun 2024 14:44:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72129#M34501</guid>
      <dc:creator>high-energy</dc:creator>
      <dc:date>2024-06-08T14:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a table name without back tick when using set variable</title>
      <link>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72154#M34505</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;It's possible that the `identifier` clause is what you're looking for (&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-names-identifier-clause.html#identifier-clause" target="_blank"&gt;https://docs.databricks.com/en/sql/language-manual/sql-ref-names-identifier-clause.html#identifier-clause&lt;/A&gt;). If so, this basic example should work:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;DECLARE mytab = '`mycatalog`.`myschema`.t1';
DECLARE mytab_suffix = 'suffix';
CREATE TABLE IF NOT EXISTS IDENTIFIER(mytab || '_' || mytab_suffix) (c1 int);
SELECT * FROM IDENTIFIER(mytab || '_' || mytab_suffix);&lt;/LI-CODE&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2024 03:33:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/create-a-table-name-without-back-tick-when-using-set-variable/m-p/72154#M34505</guid>
      <dc:creator>brockb</dc:creator>
      <dc:date>2024-06-09T03:33:12Z</dc:date>
    </item>
  </channel>
</rss>

