[ad_1]
Within a Snowflake JavaScript stored procedure, I would like to retrieve the executing procedure’s database name (and preferably schema name too). Can this be done? And if so, how?
Note: It cannot depend on the current session, as that could be with a different database, while a different database’s stored procedure is being called using the fully-qualified name. (i.e. <database>.<schema>.<procedure>
)
Also note: It’s not as simple as statically defining it within the procedure, as this is something that could be deployed to multiple databases (i.e. different environments), and it’s not practical to change the SP body for each one.
Some conceptual aproaches could be…
Using a built-in JavaScript object like this one (which gets just the procedure name):
var proc_name = Object.keys(this)[0];
Using a built-in SQL function like this one (which retrieves the session’s DB, not the procedure’s DB):
var result = snowflake.execute({sqlText: 'select current_database()'});
result.next();
var db_name = result.getColumnValue(1);
Or, another creative solution?
If not possible, maybe someone can point me to an existing Snowflake feature request?
[ad_2]