<budget_name>!GET_SERVICE_TYPE_USAGE

View the credit usage for a budget by service type.

See also:

<budget_name>!GET_SPENDING_HISTORY

Syntax

<budget_name>!GET_SERVICE_TYPE_USAGE( SERVICE_TYPE => '<service_type>' ,
                                      TIME_DEPART => '<time_interval>' ,
                                      USER_TIMEZONE => '<timezone>' ,
                                      TIME_LOWER_BOUND => <constant_expr> ,
                                      TIME_UPPER_BOUND => <constant_expr>
                                    )
Copy

Arguments

SERVICE_TYPE => service_type

The service type used to limit results.

Valid values:

Type of service that is consuming credits, which can be one of the following:

  • AUTO_CLUSTERING

  • MATERIALIZED_VIEW

  • PIPE

  • QUERY_ACCELERATION

  • SEARCH_OPTIMIZATION

  • SERVERLESS_TASK

  • SNOWPIPE_STREAMING

  • WAREHOUSE_METERING

  • WAREHOUSE_METERING_READER

TIME_DEPART => time_interval

Time interval used to delineate usage records. Each row displays service usage by the specified time interval.

Valid values:

  • HOUR, hour

  • DAY, day

  • WEEK, week

USER_TIMEZONE => timezone

String specifying the user’s timezone. Budget metering is based on the UTC timezone.

TIME_LOWER_BOUND => constant_expr

The start of the time range during which the spending occurred.

TIME_UPPER_BOUND => constant_expr

The end of the time range during which the spending occurred.

Returns

The function returns the following columns:

Column Name

Data Type

Description

START_TIME

TIMESTAMP_TZ

Date and time the usage occurred.

ENTITY_ID

NUMBER

Internal identifier for the object in the budget.

NAME

VARCHAR

Name of the metered object.

CREDITS_USED

FLOAT

Number of credits used. This is the sum of CREDITS_COMPUTE and CREDITS_CLOUD.

CREDITS_COMPUTE

FLOAT

Number of compute credits used.

CREDITS_CLOUD

FLOAT

Number of cloud service credits used.

Access Control Requirements

  • The following minimum privileges and roles are required to view results for custom budgets:

    • A role with any instance role for the budget instance.

    • A role granted the USAGE privilege on the database and schema that contains the budget instance.

  • The following role is required to view results for the account budget:

    A role with any application role for the account budget.

Usage Notes

For timezone, you can specify a time zone name or a link name from release 2021a of the IANA Time Zone Database (e.g. America/Los_Angeles, Europe/London, UTC, Etc/GMT, etc.).

Note

  • Time zone names are case-sensitive and must be enclosed in single quotes (e.g. 'UTC').

  • Snowflake does not support the majority of timezone abbreviations (e.g. PDT, EST, etc.) because a given abbreviation might refer to one of several different time zones. For example, CST might refer to Central Standard Time in North America (UTC-6), Cuba Standard Time (UTC-5), and China Standard Time (UTC+8).

Examples

View the daily credits spent for each warehouse in the past week for the account budget:

CALL snowflake.local.account_root_budget!GET_SERVICE_TYPE_USAGE(
   SERVICE_TYPE => 'WAREHOUSE_METERING',
   TIME_DEPART => 'day',
   USER_TIMEZONE => 'UTC',
   TIME_LOWER_BOUND => dateadd('day', -7, current_timestamp()),
   TIME_UPPER_BOUND => current_timestamp()
);
Copy

Error Messages

The following scenarios can help you troubleshoot issues that can occur.

Error

001044 (42P13): SQL compilation error: error line 0 at position -1
Invalid argument types for function 'GET_SERVICE_TYPE_USAGE':
(VARCHAR(X), VARCHAR(X), VARCHAR(X), VARCHAR(X))

Cause

You called the method with invalid arguments or the wrong number of arguments.

Solution

Check that the arguments you use to call the method are valid and that you’ve included all required arguments.

Error

002151 (22023): Uncaught exception of type 'STATEMENT_ERROR' on line 16
at position 23 : SQL compilation error: [:TIME_DEPART] is not a valid
date/time component for function DATE_TRUNC.

Cause

The TIME_DEPART argument is an invalid string.

Solution

Use one of the valid values listed above.

Error

100094 (22000): Uncaught exception of type 'STATEMENT_ERROR' on line 16
at position 23 : Unknown timezone: '<invalid_timezone>'

Cause

The USER_TIMEZONE argument is an invalid string.

Solution

Use a valid timezone string. For more information, see the Usage Notes above.