Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
How to dynamically retrieve the executing procedure's database name in Snowflake?

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?

Why?

  1. The procedure builds dynamic SQL for tables expected to be in the same database as the SP, using fully-qualified object names.
  2. The goal is for both these (semi-generic) tables and the procedure to be deployed to multiple databases as appropriate, using identical table/procedure DDL (stored in VCS).
  3. If really curious, this is for automated provisioning of multi-tenant row-level security access via Tableau, to a variety of different environments & databases in Snowflake.

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 approaches 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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!