Translation specification for the ACTIVITY_COUNT status variable.
Important Notice: Migration of Documentation Website
Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:
For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].
Thank you for your understanding.
Description
The ACTIVITY_COUNT status variable returns the number of rows affected by an SQL DML statement in an embedded SQL or stored procedure application. For more information check here.
There is no direct equivalent in Snowflake. However, there is a workaround to emulate the ACTIVITY_COUNT's behavior. One must simply use the following query:
SELECT $1FROMTABLE(RESULT_SCAN(LAST_QUERY_ID()));
This query retrieves and returns the first column of the result set from the last executed query in the current session. Furthermore, $1 can be replaced by "number of rows inserted", "number of rows updated" or "number of rows deleted" based on the query type.
As expected, this translation behaves like its Teradata counterpart only when no other queries besides the SQL DML statement are executed before calling LAST_QUERY_ID.
Sample Source Patterns
Setup data
Teradata
Snowflake
Supported usage
Teradata
Snowflake
Known Issues
If ACTIVITY_COUNT is called twice or more times before executing a DML statement, the transformation might not return the expected values. Check here.
If ACTIVITY_COUNT is called after a non DML statement was executed, the transformation will not return the expected values. Check here.
ACTIVITY_COUNT requires manual fixing when inside a SELECT/SET INTO VARIABLE statement and was not able to be identified as a column name. Check here.
REPLACE PROCEDURE UpdateEmployeeSalaryAndLog ()
BEGIN
DECLARE row_count1 INT;
UPDATE employees
SET salary = 80000
WHERE department_id = 10;
-- Get the ACTIVITY_COUNT
SET row_count1 = ACTIVITY_COUNT;
-- Insert the ACTIVITY_COUNT into the activity_log table
INSERT INTO activity_log (operation, row_count)
VALUES ('UPDATE WHERE dept=10', row_count1);
END;
CALL UpdateEmployeeSalaryAndLog();
SELECT * FROM ACTIVITY_LOG;