Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we pass list or array as parameter to JavaScript procedure in snowflake?

Can we pass list or array as parameter to javascript procedure in snowflake?

I am working on procedure which would run weekly and delete a week old data from certain tables. Instead of creating task for individual table, I want to pass table names as list/array.

Please guide.

Thanks in advance!

like image 943
Sujata Shakya Avatar asked Jan 25 '23 19:01

Sujata Shakya


1 Answers

Yes, you can pass an array into a Snowflake JavaScript stored procedure. Here's a sample:

create or replace procedure test(ARR array)
returns string
language javascript
as
$$
    var i; 
    var out = "";

    // Remember to capitalize variables input to the stored procedure definition
    for(i = 0; i < ARR.length; i++){       
        out += ARR[i];
        if (i < ARR.length - 1) out += ", ";
    }
    return out;
$$;


call test(array_construct('TABLE_1', 'TABLE_2', 'TABLE_3'));
like image 172
Greg Pavlik Avatar answered May 16 '23 05:05

Greg Pavlik