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

514
Views
Cláusula Try&catch en secuencias de comandos de copos de nieve

Me pregunto si hay un equivalente de intentar capturar bloques de javascript en sql puro en Snowflake. Quiero tener un procedimiento que verifique todas las vistas y haga algo con ellas, pero algunas de las vistas no son válidas y quiero omitirlas. La versión de javascript se ve así:

 create or replace procedure test_views_js() returns varchar language javascript as $$ var sql = "select table_name from INFORMATION_SCHEMA.views where table_schema='TEST'"; var stmt = snowflake.createStatement ({sqlText:sql}); var result_set = stmt.execute(); var cnt = 0; while (result_set.next()){ try{ var sql_text = "select count(*) from "+result_set.getColumnValue(1); var stmt2 = snowflake.createStatement ({sqlText:sql_text}); var r = stmt2.execute(); r.next(); cnt+=r.getColumnValue(1); }catch (err){ continue } } return cnt; $$

¿Puedo lograr el mismo resultado con sql?

ACTUALIZAR

Recibo un error de sintaxis cuando intento poner una excepción en el bucle. Cuando está en un lugar diferente, la sintaxis es válida, pero 'break is outside of loop' . ¿Tal vez hay algún error tipográfico obvio que no puedo ver?

 create or replace procedure test_views() returns integer not null language sql as declare sel varchar; row_cnt integer default 0; res resultset default (select table_name from INFORMATION_SCHEMA.views where table_schema='TEST') ; c1 cursor for res; begin for row_variable in c1 do row_cnt:= (select count(*) from view_test); exception when statement_error then continue; end for; return row_cnt; end;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Sí, hay construcciones RAISE/EXCEPTION documentadas aquí: https://docs.snowflake.com/en/developer-guide/snowflake-scripting/exceptions.html

about 4 years ago · Juan Pablo Isaza Report

0

Es posible usar una excepción dentro del ciclo. En vez de:

 for row_variable in c1 do row_cnt:= (select count(*) from view_test); exception when statement_error then continue; end for;

Todo el código debe envolverse con su propio bloque BEGIN EXCEPTION END .

 create or replace procedure test_views() returns integer not null language sql as declare sel varchar; row_cnt integer default 0; res resultset default (select table_name from INFORMATION_SCHEMA.views where table_schema='TEST') ; c1 cursor for res; begin for row_variable in c1 do begin row_cnt:= (select count(*) from view_test); exception when other then continue; end; end for; return row_cnt; end;
about 4 years ago · Juan Pablo Isaza Report
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!