<?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: SQL function does not work in 'Create Function' in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/sql-function-does-not-work-in-create-function/m-p/71961#M34450</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/45194"&gt;@Lily99&lt;/a&gt;&amp;nbsp;, I hope this message finds you well.&lt;/P&gt;
&lt;P&gt;Could you please try the code below and let me know the results?&lt;/P&gt;
&lt;P&gt;CREATE OR REPLACE FUNCTION fn_abc(var1 STRING, var2 STRING)&lt;/P&gt;
&lt;P&gt;RETURNS DOUBLE&lt;BR /&gt;COMMENT 'test function'&lt;BR /&gt;RETURN SELECT&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CASE&lt;BR /&gt;&amp;nbsp; &amp;nbsp; WHEN EXISTS(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT COUNT(1)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM tablea f INNER JOIN tableb t WHERE&lt;I&gt;&amp;nbsp;lower&lt;/I&gt;(f.col1) = t.col1)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; THEN 10.5&lt;BR /&gt;&amp;nbsp; &amp;nbsp; END;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Lucas Rocha&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jun 2024 22:53:51 GMT</pubDate>
    <dc:creator>lucasrocha</dc:creator>
    <dc:date>2024-06-06T22:53:51Z</dc:date>
    <item>
      <title>SQL function does not work in 'Create Function'</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-function-does-not-work-in-create-function/m-p/4055#M886</link>
      <description>&lt;P&gt;This SQL statement works fine by itself&lt;/P&gt;&lt;P&gt;&lt;B&gt;                  SELECT COUNT(1) &lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;                  FROM tablea f &lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;                  INNER JOIN tableb t ON &lt;I&gt;lower&lt;/I&gt;(f.col1) = t.col1&lt;/B&gt;&lt;/P&gt;&lt;P&gt;but if I want to use it inside a function:&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;&lt;B&gt;CREATE OR REPLACE FUNCTION fn_abc(var1 STRING, var2 STRING)&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;RETURNS DOUBLE&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;COMMENT 'test function'&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;RETURN SELECT&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&amp;nbsp; &amp;nbsp; CASE&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&amp;nbsp; &amp;nbsp; WHEN EXISTS(&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT COUNT(1) &lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM tablea f INNER JOIN tableb t ON&lt;I&gt; lower&lt;/I&gt;(f.col1) = t.col1)&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&amp;nbsp; &amp;nbsp; THEN 10.5&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&amp;nbsp; &amp;nbsp; END;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;I got an error:&lt;/P&gt;&lt;P&gt;AnalysisException: [UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_COLUMN_IS_NOT_ALLOWED_IN_PREDICATE] Unsupported subquery expression: Correlated column is not allowed in predicate: (lower(Col1#54978) = lower(outer(col1#54938)))&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;can someone give me an idea on why this is happening and how to work around it? thanks &lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 17:28:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-function-does-not-work-in-create-function/m-p/4055#M886</guid>
      <dc:creator>Lily99</dc:creator>
      <dc:date>2023-05-23T17:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: SQL function does not work in 'Create Function'</title>
      <link>https://community.databricks.com/t5/data-engineering/sql-function-does-not-work-in-create-function/m-p/71961#M34450</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/45194"&gt;@Lily99&lt;/a&gt;&amp;nbsp;, I hope this message finds you well.&lt;/P&gt;
&lt;P&gt;Could you please try the code below and let me know the results?&lt;/P&gt;
&lt;P&gt;CREATE OR REPLACE FUNCTION fn_abc(var1 STRING, var2 STRING)&lt;/P&gt;
&lt;P&gt;RETURNS DOUBLE&lt;BR /&gt;COMMENT 'test function'&lt;BR /&gt;RETURN SELECT&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CASE&lt;BR /&gt;&amp;nbsp; &amp;nbsp; WHEN EXISTS(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT COUNT(1)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM tablea f INNER JOIN tableb t WHERE&lt;I&gt;&amp;nbsp;lower&lt;/I&gt;(f.col1) = t.col1)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; THEN 10.5&lt;BR /&gt;&amp;nbsp; &amp;nbsp; END;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Lucas Rocha&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2024 22:53:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sql-function-does-not-work-in-create-function/m-p/71961#M34450</guid>
      <dc:creator>lucasrocha</dc:creator>
      <dc:date>2024-06-06T22:53:51Z</dc:date>
    </item>
  </channel>
</rss>

