Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

480
Vistas
How to dynamically select columns from a given table in snowflake stored procedure?

I am trying to create a procedure that choose columns dynamically from two table. I have already hardcoded query which works fine.

#Existing query

create table mydb.result_table as 
select 
t1.id,
t1.name,
t1.place,
t1.product
t1.prize
t2.id,
t2.name,
t2.place,
t2.product,
t2.prize
from source_db.source_table t1
full outer join target_db_target_table t2 on 
t1.id=t2.id and t1.name=t2.name
where t1.place<>t2.place

Now i need to create a procedure which basically select column dynamically from given table name and join both with given keys

so something like below

CREATE OR REPLACE PROCEDURE result(source_db varchar, source_table VARCHAR, targt_db varchar, target_table VARCHAR, key_join varchar<not sure can pass list>, filter_col varchar )
returns string not null
language javascript
as
$$
var query= `create table mydb.result_table as 
select
t1.<all columns from source_db and source_table>
t2.<all columns from targt_db and target_table >
from <source_db and source_table> as t1
full outer join  <target_db_target_table> as t2
on <key_join> where <t1.filter_col <> t2.filter_col>
`
return 'success';
$$;

i don't see example of selecting columns dynamically for this kind of use case. Any solution to this?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to query the information schema for the list of columns in each table and use the result to dynamically build your SQL statement.

You also need to be aware of the same column name existing in multiple tables as you obviously can’t have the same column appearing multiple times in a table - so you’ll need to dynamically rename columns as appropriate

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just query the INFORMATION_SCHEMA.COLUMNS view to access the table's columns and then you can build your query dynamically:

https://docs.snowflake.com/en/sql-reference/info-schema/columns.html

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda