<budget_name>!ADD_RESOURCE

Add an object to a custom budget. The object must be added by reference.

See also:

<budget_name>!REMOVE_RESOURCE, <budget_name>!GET_LINKED_RESOURCES

语法

<budget_name>!ADD_RESOURCE( { '<object_reference>' | <reference_statement> } )

实参

'object_reference'

The serialized string representation that resolves to an object. This string is the output of the SYSTEM$REFERENCE function.

reference_statement

A SYSTEM$REFERENCE statement that creates a reference for the object to be added to the budget.

Note

If you want to add a Snowflake Native App to a budget, when you call SYSTEM$REFERENCE, specify 'DATABASE' (not 'APPLICATION') for the object_type argument.

See Adding a Snowflake Native App to a budget.

返回

返回一个 VARCHAR 值,用于指明对象是否已成功添加到预算中。例如:

Successfully added resource to resource group

If the object could not be added to the budget, the function returns an error message. See You can’t add or remove objects from a custom budget.

访问控制要求

要为自定义预算调用此方法,需要具备以下权限和角色:

  • ADMIN instance role for the budget instance.
  • 对包含预算实例的数据库和架构的 USAGE 权限。
  • 对包含该被添加对象的数据库和架构的 USAGE 权限(对于架构对象)。
  • 被添加对象的 APPLYBUDGET 权限。

For more information, see Budgets roles and privileges.

使用说明

  • 您只能将对象添加到 自定义预算
  • If you are directly adding individual objects, you can only add an object to one custom budget. In this case, if an object is currently included in one custom budget and you add that object to a second custom budget, Budgets removes the object from the first custom budget without issuing a warning.

    This behavior does not apply to using tags to add objects to budgets; an object with one or more tags can be included in multiple custom budgets if you are using tags to add the object to the budgets.

  • You cannot create a reference for the SNOWFLAKE database; and you cannot add it to a budget.
  • Calling this method does not return the object. Because of this, you can’t use method chaining to call another method on the return value of this method. Instead, call each method in a separate SQL statement.

示例

以下示例演示了如何将对象添加到自定义预算:

将表添加到预算

  • The following example creates and returns a reference for the t1 table:

    SELECT SYSTEM$REFERENCE('TABLE', 't1', 'SESSION', 'APPLYBUDGET');

该语句会在输出中返回引用。

ENT_REF_TABLE_5862683050074_5AEB8D58FB3ACF249F2E35F365A9357C46BB00D7

The following statement uses the string literal for this reference to add the t1 table to the budget_db.budget_schema.my_budget budget:

CALL budget_db.budget_schema.my_budget!ADD_RESOURCE(
  'ENT_REF_TABLE_5862683050074_5AEB8D58FB3ACF249F2E35F365A9357C46BB00D7');
  • The following example adds the t2 table to the budget_db.budget_schema.my_budget budget, using a SQL statement to specify the reference:
    CALL budget_db.budget_schema.my_budget!ADD_RESOURCE(
      SELECT SYSTEM$REFERENCE('TABLE', 't2', 'SESSION', 'APPLYBUDGET'));

Adding a Snowflake Native App to a budget

The following example adds the my_app application to the budget_db.budget_schema.my_budget budget.

Note that when calling SYSTEM$REFERENCE, you must pass in 'DATABASE' (not 'APPLICATION') for the object_type argument.

CALL budget_db.budget_schema.my_budget!ADD_RESOURCE(
  SELECT SYSTEM$REFERENCE('DATABASE', 'my_app', 'SESSION', 'APPLYBUDGET'));

错误消息

For a list of common error messages and their causes and solutions, see You can’t add or remove objects from a custom budget.