Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda