default date value to store in a table in snowflake

Viewed 70

I created below snowflake procedure and from that procedure I want to insert default date value into a table. Below is the script.

create or replace procedure test_dt() returns string not null language
 javascript //execute as owner 
as 
$$ 
try { 
    var c_dt=`select current_date()`; 
    snowflake.execute({sqlText:c_dt});

    var sql_query = `insert into test_date values (:1)`;
    var resultSet = snowflake.execute( {sqlText: sql_query, binds:c_dt}); 
}
catch(err) {
    return err.message; 
} 
$$;

call test_dt();

while executing the procedure I am getting below error.

"Date 'select current_date()' is not recognized"

Please help me on this.

1 Answers

you are binding the "date" in the second query, to the input sql that "gets the current_date()" and not the actual result, thus it's the same as

insert into test_date values ('select current_date()');

so you ether want to save the result of the first query OR just use the current date aka CURRENT_DATE

insert into test_date values (CURRENT_DATE);

create or replace procedure test_dt() returns string not null language
 javascript //execute as owner 
as 
$$ 
try { 
    var sql_query = `insert into test_date values (current_date)`;
    var resultSet = snowflake.execute( {sqlText: sql_query}); 
}
catch(err) {
    return err.message; 
} 
$$;```
Related