I created a UDF that takes 4 parameters and outputs a DDL statement
select * from table(my_udf('some_text',some_integer,some_integer,'some_text''));
Here is one sample of a DDL statement the SQL UDF outputs as a table with one row
create or replace temporary view some_view as
select * from some_table1 union all
select * from some_table2;
How can I create a Javascript based procedure that basically takes the same parameters as my SQL UDF and executes the DDL statement. I am not so familiar with Javascript, which is why I left all the heavy lifting to SQL so I could keep the stored procedure as simple as possible in case I need to replicate it for a different use case.
This is my attempt so far based on the examples I came across. There is probably a lot wrong my code, but if someone could point me in the right direction, that'd be huge
create or replace temporary procedure jvs_udf(PAR_1 varchar, PAR_2 number, PAR_3 number, ARG_4 varchar)
returns string not null
language Javascript
as
$$
sql_command = 'select * from table(my_udf(' + PAR_1 + ',' + PAR_2 + ',' + PAR_3 + ',' + PAR_4 + '))' ;
var stmt = snowflake.createStatement({sqlText: sql_command}).execute();
return --how do I also get it to return the message I would have gotten had I run DDL in UI?
$$;