trying to return a variable value from a procedure in snowflake. And it is getting errored out

Viewed 67
CREATE OR REPLACE PROCEDURE dbo.test()
RETURNS varchar  null 
LANGUAGE JAVASCRIPT
execute as caller
AS 
$$
set MY_VAR =1;
return $MY_VAR;
$$
;

If I execute as below I am facing the error . Message as shown below call dbo.test();

//ERROR: JavaScript compilation error: Uncaught SyntaxError: Unexpected identifier in TEST at 'set MY_VAR =1;' position 4
1 Answers
CREATE OR REPLACE PROCEDURE test()
RETURNS float not null 
LANGUAGE JAVASCRIPT
execute as caller
AS 
$$
var MY_VAR =1.1;
return MY_VAR;
$$
;


call <database>.<schema>.test();

gives:

1.1

so given you are trying to return a number value, I changed it to float instead of varchar, but after testing ether is fine.

But mostly I changed from set to var to declare your variable. The other valid keyword is let, which also works.

Related