<?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 [Error] [SECRET_FUNCTION_INVALID_LOCATION]: While running secret function with create or replace in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/error-secret-function-invalid-location-while-running-secret/m-p/38079#M26555</link>
    <description>&lt;P&gt;Hi, recently we made an upgrade to our databricks warehouse, transitioning from SQL Classic to SQL PRO.&lt;BR /&gt;However, we started encountering the following error message when attempting to execute the "CREATE or REPLACE" table query&amp;nbsp;with the &lt;EM&gt;&lt;STRONG&gt;secret function&lt;/STRONG&gt;&lt;/EM&gt; that was previously working fine with the Classic warehouse.&lt;/P&gt;&lt;H4&gt;Error Message:&lt;/H4&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[SECRET_FUNCTION_INVALID_LOCATION] Cannot execute INSERT command with one or more non-encrypted references to the SECRET function; please encrypt the result of each such function call with AES_ENCRYPT and try the command again.&lt;/LI-CODE&gt;&lt;H4&gt;Steps to reproduce:&lt;/H4&gt;&lt;P&gt;i) Create an employee table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;create or replace table &amp;lt;catalog_name&amp;gt;.default.employee (
    id int,
    name string,
    email string,
    joining_date date
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ii) Inserted data in employee table and encrypted the &lt;EM&gt;&lt;STRONG&gt;email&lt;/STRONG&gt;&lt;/EM&gt; column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;with emp_data as (
    select 123 as id, 'John' as name, 'john.doe@gmail.com' as email, '2022-11-01' as joining_date
    union all
    select 456, 'Joe', 'joe@gmail.com', '2023-01-02'
    union all
    select 789, 'Andy', 'andy@gmail.com', '2022-12-15'
)

insert into &amp;lt;catalog_name&amp;gt;.default.employee
select
    id,
    name,
    base64(
        aes_encrypt(
            email,
            secret(&amp;lt;scope_name&amp;gt;, &amp;lt;secret_key&amp;gt;)
        )
    ),
    joining_date
from emp_data;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;iii) Create a new table that will have details of all employee who joined in 2023 with decrypted hashed email:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;create or replace table &amp;lt;catalog_name&amp;gt;.default.employee_2023
select
    id,
    name,
    sha2(
        cast(
            aes_decrypt(
                unbase64(email),
                secret(&amp;lt;scope_name&amp;gt;, &amp;lt;secret_key&amp;gt;)
            ) as string
        ), 256
    ) as email,
    joining_date
from &amp;lt;catalog_name&amp;gt;.default.employee
where year(joining_date) = '2023';&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: &lt;FONT color="#FF6600"&gt;&amp;lt;catalog_name&amp;gt;&lt;/FONT&gt;, &lt;FONT color="#FF6600"&gt;&amp;lt;scope_name&amp;gt;&lt;/FONT&gt; and &lt;FONT color="#FF6600"&gt;&amp;lt;secret_key&amp;gt;&lt;/FONT&gt; needs to be updated before running the above code.&lt;/P&gt;&lt;H4&gt;Expected Behaviour:&lt;/H4&gt;&lt;P&gt;Table employee_2023 should contain the details of all employee who joined in 2023 with decrypted hashed email.&lt;/P&gt;&lt;H4&gt;Observed Behaviour:&lt;/H4&gt;&lt;P&gt;While decrypting the email column in employee_2023 table creation, databricks is throwing the error&lt;BR /&gt;(SECRET_FUNCTION_INVALID_LOCATION) which is mentioned above.&lt;/P&gt;&lt;H4&gt;Version:&lt;/H4&gt;&lt;P&gt;Databricks Runtime Version: 12.2 LTS&lt;BR /&gt;JDBC URL: 2.6.25 or later&lt;BR /&gt;Channel: Current(v 2023.30)&lt;/P&gt;&lt;H4&gt;Suggestion:&lt;/H4&gt;&lt;P&gt;The documentation(&lt;A href="https://docs.databricks.com/error-messages/index.html" target="_blank" rel="noopener"&gt;https://docs.databricks.com/error-messages/index.html&lt;/A&gt;) didn't provide necessary information regarding the resolution of issue. It will be very helpful if the document is updated with the proper and detailed information about the issue.&lt;/P&gt;&lt;P&gt;Also we would really appreciate&amp;nbsp;&lt;SPAN&gt;any help or guidance you can provide to resolve this issue.&amp;nbsp;&lt;/SPAN&gt;Waiting for the solution and expecting to get some positive response soon.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2023 08:34:21 GMT</pubDate>
    <dc:creator>sumit23</dc:creator>
    <dc:date>2023-08-01T08:34:21Z</dc:date>
    <item>
      <title>[Error] [SECRET_FUNCTION_INVALID_LOCATION]: While running secret function with create or replace</title>
      <link>https://community.databricks.com/t5/data-engineering/error-secret-function-invalid-location-while-running-secret/m-p/38079#M26555</link>
      <description>&lt;P&gt;Hi, recently we made an upgrade to our databricks warehouse, transitioning from SQL Classic to SQL PRO.&lt;BR /&gt;However, we started encountering the following error message when attempting to execute the "CREATE or REPLACE" table query&amp;nbsp;with the &lt;EM&gt;&lt;STRONG&gt;secret function&lt;/STRONG&gt;&lt;/EM&gt; that was previously working fine with the Classic warehouse.&lt;/P&gt;&lt;H4&gt;Error Message:&lt;/H4&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[SECRET_FUNCTION_INVALID_LOCATION] Cannot execute INSERT command with one or more non-encrypted references to the SECRET function; please encrypt the result of each such function call with AES_ENCRYPT and try the command again.&lt;/LI-CODE&gt;&lt;H4&gt;Steps to reproduce:&lt;/H4&gt;&lt;P&gt;i) Create an employee table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;create or replace table &amp;lt;catalog_name&amp;gt;.default.employee (
    id int,
    name string,
    email string,
    joining_date date
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ii) Inserted data in employee table and encrypted the &lt;EM&gt;&lt;STRONG&gt;email&lt;/STRONG&gt;&lt;/EM&gt; column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;with emp_data as (
    select 123 as id, 'John' as name, 'john.doe@gmail.com' as email, '2022-11-01' as joining_date
    union all
    select 456, 'Joe', 'joe@gmail.com', '2023-01-02'
    union all
    select 789, 'Andy', 'andy@gmail.com', '2022-12-15'
)

insert into &amp;lt;catalog_name&amp;gt;.default.employee
select
    id,
    name,
    base64(
        aes_encrypt(
            email,
            secret(&amp;lt;scope_name&amp;gt;, &amp;lt;secret_key&amp;gt;)
        )
    ),
    joining_date
from emp_data;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;iii) Create a new table that will have details of all employee who joined in 2023 with decrypted hashed email:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;create or replace table &amp;lt;catalog_name&amp;gt;.default.employee_2023
select
    id,
    name,
    sha2(
        cast(
            aes_decrypt(
                unbase64(email),
                secret(&amp;lt;scope_name&amp;gt;, &amp;lt;secret_key&amp;gt;)
            ) as string
        ), 256
    ) as email,
    joining_date
from &amp;lt;catalog_name&amp;gt;.default.employee
where year(joining_date) = '2023';&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: &lt;FONT color="#FF6600"&gt;&amp;lt;catalog_name&amp;gt;&lt;/FONT&gt;, &lt;FONT color="#FF6600"&gt;&amp;lt;scope_name&amp;gt;&lt;/FONT&gt; and &lt;FONT color="#FF6600"&gt;&amp;lt;secret_key&amp;gt;&lt;/FONT&gt; needs to be updated before running the above code.&lt;/P&gt;&lt;H4&gt;Expected Behaviour:&lt;/H4&gt;&lt;P&gt;Table employee_2023 should contain the details of all employee who joined in 2023 with decrypted hashed email.&lt;/P&gt;&lt;H4&gt;Observed Behaviour:&lt;/H4&gt;&lt;P&gt;While decrypting the email column in employee_2023 table creation, databricks is throwing the error&lt;BR /&gt;(SECRET_FUNCTION_INVALID_LOCATION) which is mentioned above.&lt;/P&gt;&lt;H4&gt;Version:&lt;/H4&gt;&lt;P&gt;Databricks Runtime Version: 12.2 LTS&lt;BR /&gt;JDBC URL: 2.6.25 or later&lt;BR /&gt;Channel: Current(v 2023.30)&lt;/P&gt;&lt;H4&gt;Suggestion:&lt;/H4&gt;&lt;P&gt;The documentation(&lt;A href="https://docs.databricks.com/error-messages/index.html" target="_blank" rel="noopener"&gt;https://docs.databricks.com/error-messages/index.html&lt;/A&gt;) didn't provide necessary information regarding the resolution of issue. It will be very helpful if the document is updated with the proper and detailed information about the issue.&lt;/P&gt;&lt;P&gt;Also we would really appreciate&amp;nbsp;&lt;SPAN&gt;any help or guidance you can provide to resolve this issue.&amp;nbsp;&lt;/SPAN&gt;Waiting for the solution and expecting to get some positive response soon.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 08:34:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/error-secret-function-invalid-location-while-running-secret/m-p/38079#M26555</guid>
      <dc:creator>sumit23</dc:creator>
      <dc:date>2023-08-01T08:34:21Z</dc:date>
    </item>
  </channel>
</rss>

