SQLROWCOUNT is a Snowflake Scripting global variable containing the number of rows affected by the most recently executed query. Use it immediately after a data-change statement to report processing results or write operational metrics. section 4.3.2 section 13.4.1
Use SQLROWCOUNT to make data-processing operations observable:
- Return a completion message that includes the affected-row count from a stored procedure. section 4.3.2
- Insert the count into a pipeline log after commands such as COPY INTO, alongside task and run-group identifiers. section 13.4.1
- Capture the value directly after the command whose result it represents; the logging INSERT follows the COPY command in the task example. section 13.4.1
Returning a load result
After a MERGE, return `Load completed. ` concatenated with SQLROWCOUNT and ` rows affected.` A procedure call can therefore produce a result such as `Load completed. 131 rows affected.`
create or replace task COPY_ORDERS_TASK
warehouse = BAKERY_WH
schedule = '10 M'
as
begin
copy into EXT.JSON_ORDERS_EXT
from (
select
$1,
metadata$filename,
current_timestamp()
from @EXT.JSON_ORDERS_STAGE
)
on_error = abort_statement;
insert into PIPELINE_LOG
select
SYSTEM$TASK_RUNTIME_INFO('CURRENT_TASK_GRAPH_RUN_GROUP_ID'),
SYSTEM$TASK_RUNTIME_INFO('CURRENT_ROOT_TASK_NAME'),
SYSTEM$TASK_RUNTIME_INFO('CURRENT_TASK_NAME'),
current_timestamp(),
:SQLROWCOUNT;
end;
Inspect the task definition to see SQLROWCOUNT recorded in PIPELINE_LOG after COPY INTO, with task runtime metadata. section 13.4.1
