cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Create function issue

greengil
Visitor

Hello - I am following some online code to create a function as follows:

-----------------------------------------

CREATE OR REPLACE FUNCTION my_catalog.my_schema.insert_data_function(
col1_value STRING,
col2_value INT
)
RETURNS BOOLEAN
COMMENT 'Inserts data into a table in Unity Catalog.'
RETURN
INSERT INTO my_catalog.my_schema.my_table (column1, column2)
VALUES (col1_value, col2_value);

-----------------------------------------

Then I got an error:

Syntax error at or near 'INTO'. SQLSTATE: 42601

It looks like function is to return do reading only and return a value but not writing something to the table.  Can you please advise?  Thanks!

1 REPLY 1

szymon_dybczak
Esteemed Contributor III

Hi @greengil ,

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.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now