How to execute a script with the below steps in Snowflake:
1.) check the environment if dev, qa, sit, prod using account url, current_account function. 2.) if the current_account is qa.snowflakcomputig.com then 3.) check if there is a table named TABLEA 4.) if YES, then rename table to TABLEB
I want to achieve this using Snowflake SQL. I know we cannot write anonymous block, could this be achieved using just SQL, session variables and any new rich functions that snowflake might provide.
SELECT current_account()
gets you this.ALTER TABLE IF EXISTS tablename RENAME TO tablename_new
would be the easiest way to accomplish this. If the table doesn't exist, nothing will happen.This logic could easily be wrapped into a stored procedure, but at the moment that would have to be Javascript, not SQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With