CURSOR
Translation reference to convert SQL Server CUROR statement to Snowflake Scripting
Some parts in the output code are omitted for clarity reasons.
Description
Microsoft SQL Server statements produce a complete result set, but there are times when the results are best processed one row at a time. Opening a cursor on a result set allows processing the result set one row at a time. You can assign a cursor to a variable or parameter with a cursor data type. For more information check here.
Sample Source Patterns
SQL Server
Notice that the following parameters are inherently supported by Snowflake Scripting.
[LOCAL].
[FORWARD_ONLY].
[FAST_FORWARD] Specifies a FORWARD_ONLY (FETCH NEXT only) and READ_ONLY
[READ_ONLY] the WHERE CURRENT OF does not exist in Snowflake Scripting.
Snowflake Scripting
Known Issues
The following parameters are not supported:
DECLARE CURSOR
[ GLOBAL ] Allows referencing the cursor name in any stored procedure or batch executed by the connection. Snowflake Scripting only allows the use of the cursor locally.
[ SCROLL ] Snowflake Scripting only support FETCH NEXT.
[ KEYSET | DYNAMIC ] If after opening a cursor and update to the table is made, these options may display some of the changes when fetching the cursor, Snowflake scripting only supports STATIC, in other words, after the cursor is opened the changes to the table are not detected by the cursor.
[SCROLL_LOCKS] Specifies that positioned updates or deletes made through the cursor are guaranteed to succeed, Snowflake Scripting cannot guarantee it.
[OPTIMISTIC] When an update or delete is made through the cursor it uses comparisons of timestamp column values, or a checksum value if the table has no timestamp column, to determine whether the row was modified after it was read into the cursor. Snowflake Scripting does not have an internal process to replicate it.
[TYPE_WARNING]
FETCH
[PRIOR | FIRST | LAST] Snowscripting only support NEXT.
[ABSOLUTE] Snowflake Scripting only supports NEXT but the behavior can be replicated.
[RELATIVE] Snowflake Scripting but the behavior can be replicated.
[ GLOBAL ] Allows referencing the cursor name in any stored procedure or batch executed by the connection. Snowflake Scripting only allows the use of the cursor locally.
FETCH without INTO is not supported.
When the FETCH statement is located inside a loop it is considered a complex pattern as it may have an impact on the Snowflake translated code performance. Check the related issues section for more information.
Fetch inside loop sample
OPEN
[ GLOBAL ] Allows referencing the cursor name in any stored procedure or batch executed by the connection. Snowflake Scripting only allows the use of the cursor locally.
CLOSE
[ GLOBAL ] Allows referencing the cursor name in any stored procedure or batch executed by the connection. Snowflake Scripting only allows the use of the cursor locally.
DEALLOCATED Removes a cursor reference and there is no equivalent in Snowflake Scripting.
WHERE CURRENT OF the use of this statement is not supported, for example:
Environment variables
@@CURSOR_ROWS
@@FETCH_STATUS
Related EWIs
SSC-FDM-TS0013: Snowflake Scripting cursor rows are not modifiable.
SSC-PRF-0003: Fetch inside a loop is considered a complex pattern, this could degrade Snowflake performance.
Last updated