'How to pass default value to stored proc in snowflake

I am writing a stored proc in Snowflake which have a VARCHAR argument, I would like to know how can I have the default value for that argument.

CREATE OR REPLACE PROCEDURE test(arg1 VARCHAR, arg2 VARCHAR)
returns VARCHAR
language JAVASCRIPT
AS
$$
sql_cmd = snowflake.createStatement ({sqlText:`SELECT * from <table> where ID = ${ARG1};`});
sql_cmd.execute();

$$;

I will call the procedure as :

CALL test (arg1, arg2);

But for arg1 I want to pass default value as 0 (zero) so that if no value is passed, it should accept it as 0(zero).

Couldn't find anything relevant for this, please help.



Solution 1:[1]

You can use overloading - create another procedure with same definition but not arguments. Define default value inside procedure body. Your overloaded procedure will be called in case a call is with no arguments.

CREATE OR REPLACE PROCEDURE test()
returns VARCHAR
language JAVASCRIPT
AS
$$

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pankaj