<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

Syntax

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

Arguments

'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.

Returns

Successfully added resource to resource group

Access Control Requirements

The following privileges and roles are required to call this method for a custom budget:

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

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

  • A role with the APPLYBUDGET privilege on the object being added.

Usage Notes

  • You can only add objects to custom budgets.

  • You cannot create a reference for the SNOWFLAKE database, and you cannot add it to a budget.

Examples

  1. Create a reference for an object and add the object to a budget.

    Create a reference for table t1:

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

    Returns:

    ENT_REF_TABLE_5862683050074_5AEB8D58FB3ACF249F2E35F365A9357C46BB00D7
    

    Add table t1 to budget my_budget in schema budget_db.budget_schema:

    CALL budget_db.budget_schema.my_budget!ADD_RESOURCE(
      'ENT_REF_TABLE_5862683050074_5AEB8D58FB3ACF249F2E35F365A9357C46BB00D7');
    
    Copy
  2. Add an object to a budget by using a SYSTEM$REFERENCE statement.

    Add table t1 to budget my_budget in schema budget_db.budget_schema:

    CALL budget_db.budget_schema.my_budget!ADD_RESOURCE(
      SELECT SYSTEM$REFERENCE('TABLE', 't2', 'SESSION', 'APPLYBUDGET'));
    
    Copy

Error Messages

The following scenarios can help you troubleshoot issues that can occur when adding resources to a custom budget.

Error

Unknown user-defined function <budget_db>.<budget_schema>.ADD_RESOURCE

Cause

The role you used to call this method does not have the ADMIN instance role.

Solution

Use a role that has the required roles and privileges to add objects to the budget. See Access Control Requirements.

Error

002003 (02000): SQL compilation error:
<object_type> '<object_name>' does not exist or not authorized.

Cause

The role you used to call this method does not have the APPLYBUDGET privilege on the object you are trying to add to the budget.

Solution

Use a role that has the required roles and privileges to add objects to the budget. See Access Control Requirements.

Error

Uncaught exception of type 'EXPRESSION_ERROR' on line 10 at position 21 :
Privilege 'APPLYBUDGET' is not authorized on the reference object.

Cause

You tried to create a reference for an object without specifying the PRIVILEGE parameter in the SYSTEM$REFERENCE statement.

Solution

Create the reference with the APPLYBUDGET privilege on the object.

Error

505001 (55000): Uncaught exception of type 'EXPRESSION_ERROR' on line 10
at position 21 : Specified object does not exist or not authorized for
the reference.

Cause

You tried to add the SNOWFLAKE database to a custom budget with an inline SYSTEM$REFERENCE statement.

Solution

The SNOWFLAKE database cannot be added to a budget. See Usage Notes above.