Skip to content

Instantly share code, notes, and snippets.

@ian-whitestone
Created March 20, 2024 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ian-whitestone/326f785d6f171ce179de7072894d6eeb to your computer and use it in GitHub Desktop.
Save ian-whitestone/326f785d6f171ce179de7072894d6eeb to your computer and use it in GitHub Desktop.
with
warehouse_periods as (
select
warehouse_name,
timestamp as valid_from,
lead(timestamp) over (partition by warehouse_name order by timestamp asc) as valid_to,
event_name = 'RESUME_WAREHOUSE' as is_active
from snowflake.account_usage.warehouse_events_history
where
-- double check these names, can't remember exact values
event_name in ('RESUME_WAREHOUSE', 'SUSPEND_WAREHOUSE')
and event_state = 'COMPLETED'
)
select
*,
iff(is_active, datediff('seconds', valid_from, valid_to), 0) as seconds_active
from warehouse_periods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment