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

244
Visualizações
Stored procedure to insert values into a staging table from another table in snowflake

Here is the stored proc, I created. But when I try to call it, I get a parse line error


Create or replace procedure insert_into_staged1()
RETURNS STRING NOT NULL
LANGUAGE JAVASCRIPT
AS
$$
var sql_cmd = `Insert into staging_table(select xyz as xyz, abc as old_abc, case when 
               rx_code in ('1234','5432') and trim(split_part(upper(abc),'*',1)) in 
                 ('GOOGLE','APPLE','SAMSUNG') then trim(split_part(upper(abc),'*',1))
            when rx_code in ('6012') and trim(split_part(upper(abc),'*',1)) else 
             coalesce(replace(abc,'\"','\''),'') end as abc_new from table2)`
 var sql = snowflake.createStatement({sqlText: sql_cmd});
 var result = sql.execute();
 return 'success';
 $$;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try this:

Create or replace procedure insert_into_staged1()
RETURNS STRING NOT NULL
LANGUAGE JAVASCRIPT
AS
$$
var sql_cmd = `
Insert into staging_table select xyz as xyz, abc as old_abc, 
case 
when rx_code in ('1234','5432') and trim(split_part(upper(abc),'*',1)) in  ('GOOGLE','APPLE','SAMSUNG') then trim(split_part(upper(abc),'*',1))
when rx_code in ('6012') and trim(split_part(upper(abc),'*',1)) then 
             coalesce(replace(abc,'\"','\'''),'') end as abc_new from table2`;
           
 var sql = snowflake.createStatement({sqlText: sql_cmd});
 var result = sql.execute();
 return 'success';
 $$;
about 4 years ago · Juan Pablo Isaza Relatório

0

I tried running your SQL statement and found that the THEN was missing in one of the case.

The corrected function added.
    --ORiginal 
    select xyz as xyz, abc as old_abc, case when 
                   rx_code in ('1234','5432') and trim(split_part(upper(abc),'*',1)) in 
                     ('GOOGLE','APPLE','SAMSUNG') then trim(split_part(upper(abc),'*',1))
                when rx_code in ('6012') and trim(split_part(upper(abc),'*',1)) else 
                 coalesce(replace(abc,'\"','\''),'') end as abc_new from table2
    
    
    --Corrected 
    select xyz as xyz, abc as old_abc, 
    case when rx_code in ('1234','5432') and trim(split_part(upper(abc),'*',1)) in ('GOOGLE','APPLE','SAMSUNG') then trim(split_part(upper(abc),'*',1))
    when rx_code in ('6012') and trim(split_part(upper(abc),'*',1)) then 'Correction added'
    else coalesce(replace(abc,'\"','\''),'') end as abc_new from table2;



create table staging_table AS
select xyz as xyz, abc as old_abc
,case when rx_code in ('1234','5432') and  trim(split_part(upper(abc),'*',1)) in ('GOOGLE','APPLE','SAMSUNG') then trim(split_part(upper(abc),'*',1))
when rx_code in ('6012') and trim(split_part(upper(abc),'*',1)) then 'missing then'
else coalesce(replace(abc,'\"','\''),'') end as abc_new 
from table2;

create or replace table  table2 (rx_code varchar2(100), split_part varchar2(100), xyz varchar2(120), abc varchar2(100));

select
    column1,
    case
        when column1=1 then 'one'
        when column1=2 then 'two'
        else 'other'
    end as result
from (values(1),(2),(3)) v;

Create or replace procedure insert_into_staged1()
RETURNS STRING NOT NULL
LANGUAGE JAVASCRIPT
AS
$$
var sql_cmd = `select xyz as xyz, abc as old_abc
,case when rx_code in ('1234','5432') and  trim(split_part(upper(abc),'*',1)) in ('GOOGLE','APPLE','SAMSUNG') then trim(split_part(upper(abc),'*',1))
when rx_code in ('6012') and trim(split_part(upper(abc),'*',1)) then 'missing then'
else coalesce(replace(abc,'\\"','\\''),'') end as abc_new 
from table2`
 var sql = snowflake.createStatement({sqlText: sql_cmd});
 var result = sql.execute();
 return 'success';
 $$;      
 
 
 call insert_into_staged1();
  
about 4 years ago · Juan Pablo Isaza Relatório
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