SSC-EWI-PG0014

Snowflake scripting cursors do not support fetch orientation

Severity

Medium

Description

In Snowflake, the FETCH cursor statement always fetches the next row in the cursor. When transforming the code, SnowConvert will transform cursor orientations that are equivalent to a FETCH NEXT as they are functionally equivalent in Snowflake, namely:

  • FETCH NEXT

  • FETCH FORWARD

  • FETCH RELATIVE 1

  • FETCH (no orientation specified)

Any other orientation is unsupported and the FETCH statement will be marked with this EWI to reflect that.

Code Example

Input Code:

IN -> PostgreSQL_01.sql
CREATE OR REPLACE PROCEDURE cursor_test()
AS $$
BEGIN
   FETCH FORWARD FROM cursor1 INTO my_var;
   FETCH FIRST FROM cursor1 INTO my_var;
   FETCH LAST FROM cursor1 INTO my_var;
END;
$$;

Output Code:

OUT -> PostgreSQL_01.sql
CREATE OR REPLACE PROCEDURE cursor_test ()
RETURNS VARCHAR
AS $$
BEGIN
   FETCH
   	cursor1 INTO my_var;
   !!!RESOLVE EWI!!! /*** SSC-EWI-PG0014 - SNOWFLAKE SCRIPTING CURSORS DO NOT SUPPORT FETCH ORIENTATION. ***/!!!
   FETCH FIRST FROM cursor1 INTO my_var;
   !!!RESOLVE EWI!!! /*** SSC-EWI-PG0014 - SNOWFLAKE SCRIPTING CURSORS DO NOT SUPPORT FETCH ORIENTATION. ***/!!!
   FETCH LAST FROM cursor1 INTO my_var;
END;
$$;

Recommendations

Last updated