Question is around Snowflake snowsql. And need to do a conditional check to see if an ETL_Date is already insert into a table and if it has; exit the stored proc. ELSE if date is not inserted go ahead and insert data and then return success(zero) and exit. Any help will be greatly appreciated. Thanks.
Starting Point: What I have done so far my code.
IF ((SELECT IFNULL(MAX(ETL_DATE),'1900-01-01') FROM DB.TABLES.test_20200909) > CURRENT_DATE() )
{RETURN 0; break;}
else insert into DB.TABLES.test_20200909 (ETL_DATE,INSERT_VALUE)
values(CURRENT_DATE(),1)
And this gives me error: SQL compilation error: syntax error line 1 at position 0 unexpected 'IF'.
Goal/End Game : Have to place this into a stored proc. Which what I have put so far is:
CREATE or replace procedure TABLE_DB.TABLES.test_20200909_1 ()
returns FLOAT
language javascript
as
$$
var test_1 =`IF ((SELECT MAX(ETL_DATE) FROM DB.TABLES.test_20200909) > CURRENT_DATE() )
{RETURN 0; break;}
else insert into DB.TABLES.test_20200909 (ETL_DATE,INSERT_VALUE)
values(CURRENT_DATE(),1)`;
var test_1_stmt = snowflake.createStatement({sqlText: test_1});
var test_1_res = test_1_stmt.execute();
return 0
$$