<?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: Create function issue in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141632#M11179</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/112558"&gt;@iyashk-DB&lt;/a&gt;&amp;nbsp;- Thank you for the tips.&amp;nbsp; Does the following sample code look correct?&amp;nbsp; Thanks for your help!&lt;/P&gt;&lt;P&gt;#################################################################&lt;BR /&gt;###### Create the stored procedure to write data to a table #####&lt;BR /&gt;%sql&lt;BR /&gt;CREATE OR REPLACE PROCEDURE myCatalog.mySchema.insert_data_procedure(&lt;BR /&gt;col1_value STRING,&lt;BR /&gt;col2_value STRING&lt;BR /&gt;)&lt;BR /&gt;LANGUAGE SQL&lt;BR /&gt;AS&lt;BR /&gt;BEGIN&lt;BR /&gt;INSERT INTO myCatalog.mySchema.myTable (column1, column2)&lt;BR /&gt;VALUES (col1_value, col2_value);&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;#######################################################################&lt;BR /&gt;###### Define to execute a parameterized call to stored procedure #####&lt;BR /&gt;import requests&lt;/P&gt;&lt;P&gt;def call_insert_data_procedure(&lt;BR /&gt;col1_value: str,&lt;BR /&gt;col2_value: str,&lt;BR /&gt;databricks_host: str,&lt;BR /&gt;databricks_token: str&lt;BR /&gt;) -&amp;gt; str:&lt;BR /&gt;"""&lt;BR /&gt;Calls the insert_data_procedure stored procedure in Databricks via the SQL Statement Execution API.&lt;/P&gt;&lt;P&gt;Args:&lt;BR /&gt;col1_value (str): Value for the first column.&lt;BR /&gt;col2_value (str): Value for the second column.&lt;BR /&gt;databricks_host (str): Databricks workspace URL.&lt;BR /&gt;databricks_token (str): Databricks personal access token.&lt;/P&gt;&lt;P&gt;Returns:&lt;BR /&gt;str: Status message.&lt;BR /&gt;"""&lt;BR /&gt;endpoint = f"{databricks_host}/api/2.0/sql/statements/"&lt;BR /&gt;headers = {&lt;BR /&gt;"Authorization": f"Bearer {databricks_token}",&lt;BR /&gt;"Content-Type": "application/json"&lt;BR /&gt;}&lt;BR /&gt;sql = (&lt;BR /&gt;"CALL myCatalog.mySchema.insert_data_procedure("&lt;BR /&gt;f"'{col1_value}', '{col2_value}');"&lt;BR /&gt;)&lt;BR /&gt;payload = {&lt;BR /&gt;"statement": sql,&lt;BR /&gt;"warehouse_id": "&amp;lt;your_warehouse_id&amp;gt;"&lt;BR /&gt;}&lt;BR /&gt;response = requests.post(endpoint, headers=headers, json=payload)&lt;BR /&gt;response.raise_for_status()&lt;BR /&gt;return "Procedure executed successfully."&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;###########################################################&lt;BR /&gt;##### Define as a tool for an agent (LangChain style) #####&lt;BR /&gt;from langchain.tools import Tool&lt;/P&gt;&lt;P&gt;insert_data_tool = Tool(&lt;BR /&gt;name="InsertDataProcedure",&lt;BR /&gt;func=lambda col1, col2: call_insert_data_procedure(&lt;BR /&gt;col1, col2, "&amp;lt;your_databricks_host&amp;gt;", "&amp;lt;your_databricks_token&amp;gt;"&lt;BR /&gt;),&lt;BR /&gt;description="Inserts data into notification_schedule using the stored procedure."&lt;BR /&gt;)&lt;/P&gt;</description>
    <pubDate>Thu, 11 Dec 2025 05:52:59 GMT</pubDate>
    <dc:creator>greengil</dc:creator>
    <dc:date>2025-12-11T05:52:59Z</dc:date>
    <item>
      <title>Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141558#M11167</link>
      <description>&lt;P&gt;Hello - I am following some online code to create a function as follows:&lt;/P&gt;&lt;P&gt;-----------------------------------------&lt;/P&gt;&lt;P&gt;CREATE OR REPLACE FUNCTION my_catalog.my_schema.insert_data_function(&lt;BR /&gt;col1_value STRING,&lt;BR /&gt;col2_value INT&lt;BR /&gt;)&lt;BR /&gt;RETURNS BOOLEAN&lt;BR /&gt;COMMENT 'Inserts data into a table in Unity Catalog.'&lt;BR /&gt;RETURN&lt;BR /&gt;INSERT INTO my_catalog.my_schema.my_table (column1, column2)&lt;BR /&gt;VALUES (col1_value, col2_value);&lt;/P&gt;&lt;P&gt;-----------------------------------------&lt;/P&gt;&lt;P&gt;Then I got an error:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Syntax error at or near 'INTO'. SQLSTATE: 42601&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It looks like function is to return do reading only and return a value but not writing something to the table.&amp;nbsp; Can you please advise?&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 06:08:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141558#M11167</guid>
      <dc:creator>greengil</dc:creator>
      <dc:date>2025-12-10T06:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141566#M11169</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/200255"&gt;@greengil&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You can't use functions to modify data. They're intended to return scalar value or table. If you need to modify content of a table use stored procedure instead.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 08:53:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141566#M11169</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-12-10T08:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141618#M11176</link>
      <description>&lt;P&gt;Thank you for the info,&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;I am attempting to create a UC 'function' which will be registered as a tool to be used by an Agent.&amp;nbsp; The agent will connect to the tool to insert some data into a table.&amp;nbsp; Will a stored procedure be able to registered as a UC function?&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 21:40:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141618#M11176</guid>
      <dc:creator>greengil</dc:creator>
      <dc:date>2025-12-10T21:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141628#M11178</link>
      <description>&lt;P&gt;In UC, the functions must be read-only; they cannot modify state (no INSERT, DELETE, MERGE, CREATE, VACUUM, etc). So I tried to create a PROCEDURE and call it; I was able to insert data into the table successfully.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-12-11 at 9.07.30 AM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/22207i332EE637A2D90111/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-12-11 at 9.07.30 AM.png" alt="Screenshot 2025-12-11 at 9.07.30 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Unity Catalog tools are really just Unity Catalog user-defined functions (UDFs) under the hood. So you can’t register a stored procedure as a UC function tool directly.&amp;nbsp;However I can think of two quick options to make an agent perform writes:&lt;BR /&gt;1) Agent code tool: Define a tool in your agent’s code that executes a parameterized CALL … via the SQL Statement Execution API or Workspace client. Agent code tools are recommended for calling REST APIs or running arbitrary code and don’t require the operation to be wrapped as a UC function.&lt;/P&gt;
&lt;P&gt;2) DBSQL MCP server (tool interoperability): Expose a general SQL execution tool via the Databricks-managed DBSQL MCP server and have the agent run parameterized SQL, including DML, under your governance model. Use this for pipeline authoring or when you want tool discovery via MCP; for read-only chatbot-style retrieval, use Genie instead.&lt;/P&gt;
&lt;P&gt;If you must keep the tool in Unity Catalog for governance and discoverability, use UC functions for read/query tools and pair them with an agent code tool (or MCP SQL tool) for mutations. UC function tools are a great fit for retrieval/transform patterns, and Databricks explicitly supports using UC UDFs as agent tools.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 03:43:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141628#M11178</guid>
      <dc:creator>iyashk-DB</dc:creator>
      <dc:date>2025-12-11T03:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141632#M11179</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/112558"&gt;@iyashk-DB&lt;/a&gt;&amp;nbsp;- Thank you for the tips.&amp;nbsp; Does the following sample code look correct?&amp;nbsp; Thanks for your help!&lt;/P&gt;&lt;P&gt;#################################################################&lt;BR /&gt;###### Create the stored procedure to write data to a table #####&lt;BR /&gt;%sql&lt;BR /&gt;CREATE OR REPLACE PROCEDURE myCatalog.mySchema.insert_data_procedure(&lt;BR /&gt;col1_value STRING,&lt;BR /&gt;col2_value STRING&lt;BR /&gt;)&lt;BR /&gt;LANGUAGE SQL&lt;BR /&gt;AS&lt;BR /&gt;BEGIN&lt;BR /&gt;INSERT INTO myCatalog.mySchema.myTable (column1, column2)&lt;BR /&gt;VALUES (col1_value, col2_value);&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;#######################################################################&lt;BR /&gt;###### Define to execute a parameterized call to stored procedure #####&lt;BR /&gt;import requests&lt;/P&gt;&lt;P&gt;def call_insert_data_procedure(&lt;BR /&gt;col1_value: str,&lt;BR /&gt;col2_value: str,&lt;BR /&gt;databricks_host: str,&lt;BR /&gt;databricks_token: str&lt;BR /&gt;) -&amp;gt; str:&lt;BR /&gt;"""&lt;BR /&gt;Calls the insert_data_procedure stored procedure in Databricks via the SQL Statement Execution API.&lt;/P&gt;&lt;P&gt;Args:&lt;BR /&gt;col1_value (str): Value for the first column.&lt;BR /&gt;col2_value (str): Value for the second column.&lt;BR /&gt;databricks_host (str): Databricks workspace URL.&lt;BR /&gt;databricks_token (str): Databricks personal access token.&lt;/P&gt;&lt;P&gt;Returns:&lt;BR /&gt;str: Status message.&lt;BR /&gt;"""&lt;BR /&gt;endpoint = f"{databricks_host}/api/2.0/sql/statements/"&lt;BR /&gt;headers = {&lt;BR /&gt;"Authorization": f"Bearer {databricks_token}",&lt;BR /&gt;"Content-Type": "application/json"&lt;BR /&gt;}&lt;BR /&gt;sql = (&lt;BR /&gt;"CALL myCatalog.mySchema.insert_data_procedure("&lt;BR /&gt;f"'{col1_value}', '{col2_value}');"&lt;BR /&gt;)&lt;BR /&gt;payload = {&lt;BR /&gt;"statement": sql,&lt;BR /&gt;"warehouse_id": "&amp;lt;your_warehouse_id&amp;gt;"&lt;BR /&gt;}&lt;BR /&gt;response = requests.post(endpoint, headers=headers, json=payload)&lt;BR /&gt;response.raise_for_status()&lt;BR /&gt;return "Procedure executed successfully."&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;###########################################################&lt;BR /&gt;##### Define as a tool for an agent (LangChain style) #####&lt;BR /&gt;from langchain.tools import Tool&lt;/P&gt;&lt;P&gt;insert_data_tool = Tool(&lt;BR /&gt;name="InsertDataProcedure",&lt;BR /&gt;func=lambda col1, col2: call_insert_data_procedure(&lt;BR /&gt;col1, col2, "&amp;lt;your_databricks_host&amp;gt;", "&amp;lt;your_databricks_token&amp;gt;"&lt;BR /&gt;),&lt;BR /&gt;description="Inserts data into notification_schedule using the stored procedure."&lt;BR /&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 05:52:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141632#M11179</guid>
      <dc:creator>greengil</dc:creator>
      <dc:date>2025-12-11T05:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141666#M11181</link>
      <description>&lt;P&gt;If you are executing that code from databricks you don't need to call it through API SQL Statement Execution, as it is not necessary overhead. Just use spark.sql("CALL myCatalog.mySchema.insert_data_procedure("&lt;BR /&gt;f"'{col1_value}', '{col2_value}');"&lt;BR /&gt;))&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 13:27:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141666#M11181</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2025-12-11T13:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141700#M11185</link>
      <description>&lt;P&gt;I tried the following and got an error.&amp;nbsp; What's the issue?&lt;/P&gt;&lt;P&gt;Here is the registered function the agent will call:&lt;/P&gt;&lt;P&gt;def myFunction(col_val1: str, col_val2: str) -&amp;gt; str:&lt;BR /&gt;"""&lt;BR /&gt;A function that will accept 2 strings from caller and insert into a table.&lt;BR /&gt;"""&lt;BR /&gt;from pyspark.sql.session import SparkSession&lt;BR /&gt;spark = SparkSession.builder.getOrCreate()&lt;BR /&gt;spark.sql(f"CALL myCatalog.mySchema.myStoredProcedure('{col_val1}', '{col_val2}');")&lt;BR /&gt;return "Data inserted successfully."&lt;/P&gt;&lt;P&gt;Then from Playground, load the Tool to the above function and ask agent to insert data.&amp;nbsp; Got the below error:&lt;/P&gt;&lt;P&gt;== Error ==&lt;BR /&gt;SystemExit: -1&lt;BR /&gt;== Stacktrace ==&lt;BR /&gt;File "&amp;lt;udfbody&amp;gt;", line 3, in main&lt;BR /&gt;spark = SparkSession.builder.getOrCreate()&lt;BR /&gt;File "/databricks/spark/python/pyspark/sql/session.py", line 574, in getOrCreate&lt;BR /&gt;else SparkContext.getOrCreate(sparkConf)&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/spark/python/pyspark/core/context.py", line 579, in getOrCreate&lt;BR /&gt;SparkContext(conf=conf or SparkConf())&lt;BR /&gt;File "/databricks/spark/python/pyspark/core/context.py", line 207, in __init__&lt;BR /&gt;SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)&lt;BR /&gt;File "/databricks/spark/python/pyspark/core/context.py", line 500, in _ensure_initialized&lt;BR /&gt;SparkContext._gateway = gateway or launch_gateway(conf)&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/spark/python/pyspark/java_gateway.py", line 63, in launch_gateway&lt;BR /&gt;SPARK_HOME = _find_spark_home()&lt;BR /&gt;^^^^^^^^^^^^^^^^^^&lt;BR /&gt;File "/databricks/spark/python/pyspark/find_spark_home.py", line 91, in _find_spark_home&lt;BR /&gt;sys.exit(-1) SQLSTATE: 39000&lt;BR /&gt;== SQL (line 1, position &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; ==&lt;BR /&gt;SELECT `myCatalog`.`mySchema`.`myStoredProcedure`("test1","test2") as output&lt;BR /&gt;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;BR /&gt;Error: Error: org.apache.spark.SparkRuntimeException: [UDF_USER_CODE_ERROR.GENERIC] Execution of function myCatalog.mySchema.myFunction(test1, test2) failed.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 21:07:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/141700#M11185</guid>
      <dc:creator>greengil</dc:creator>
      <dc:date>2025-12-11T21:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142035#M11210</link>
      <description>&lt;P&gt;There is no SparkSession inside UDF function. Just add the procedure directly to playground.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HubertDudek_0-1765918539064.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/22352i735C7753B091619C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HubertDudek_0-1765918539064.png" alt="HubertDudek_0-1765918539064.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Dec 2025 20:56:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142035#M11210</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2025-12-16T20:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142047#M11212</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/25346"&gt;@Hubert-Dudek&lt;/a&gt;&amp;nbsp;- I tried that, and got the below error.&amp;nbsp; I verified that all the names/paths are correct.&amp;nbsp; I even tried to place the procedure under dev.default, but same issue.&amp;nbsp; Could you please advise?&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;Error: org.apache.spark.sql.AnalysisException: [UNRESOLVED_ROUTINE] Cannot resolve routine `dev`.`mySchema`.`myProcedure` on search path [`system`.`builtin`, `system`.`session`, `dev`.`default`].&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2025 06:37:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142047#M11212</guid>
      <dc:creator>greengil</dc:creator>
      <dc:date>2025-12-17T06:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142113#M11213</link>
      <description>&lt;P&gt;And you are adding the same way I did in the screenshot I attached?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2025 18:16:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142113#M11213</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2025-12-17T18:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create function issue</title>
      <link>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142121#M11215</link>
      <description>&lt;P&gt;Yes, exactly same.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 00:10:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/create-function-issue/m-p/142121#M11215</guid>
      <dc:creator>greengil</dc:creator>
      <dc:date>2025-12-18T00:10:53Z</dc:date>
    </item>
  </channel>
</rss>

