Skip to content

Instantly share code, notes, and snippets.

@lgavish
Last active May 7, 2021
Embed
What would you like to do?
Extracting query logs from Snowflake
SELECT
"QUERY_TEXT",
"DATABASE_NAME",
"SCHEMA_NAME",
"QUERY_TYPE",
"USER_NAME",
"ROLE_NAME",
"EXECUTION_STATUS",
"START_TIME",
"END_TIME",
"TOTAL_ELAPSED_TIME",
"BYTES_SCANNED",
"ROWS_PRODUCED",
"SESSION_ID",
"QUERY_ID",
"QUERY_TAG",
"WAREHOUSE_NAME",
"ROWS_INSERTED",
"ROWS_UPDATED",
"ROWS_DELETED",
"ROWS_UNLOADED"
FROM snowflake.account_usage.query_history
WHERE
start_time BETWEEN to_timestamp_ltz('2021-01-01 00:00:00.000000+00:00') AND to_timestamp_ltz('2021-01-01 01:00:00.000000+00:00')
AND QUERY_TYPE NOT IN ('DESCRIBE', 'SHOW')
AND (DATABASE_NAME IS NULL OR DATABASE_NAME NOT IN ('UTIL_DB', 'SNOWFLAKE'))
AND ERROR_CODE is NULL
ORDER BY start_time DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment