<budget_name>!SET_RESOURCE_TAGS¶
Adds tags to a custom budget so that resources that are tagged with the specified tag-value pairs are included in the budget.
You can configure the budget so that a resource is included if it is tagged with any of the specified tags (UNION) or configure it so a resource is included only if they are tagged with all of the specified tags (INTERSECTION).
Calling the method replaces any existing tags that were added to the budget.
Syntax¶
<budget_name>!SET_RESOURCE_TAGS( <tag-pairs>, <operation_mode> )
Arguments¶
tag_pairsAn ARRAY value that specifies tag references and tag values.
A tag reference is a serialized string representation that resolves to a tag. This string is the output of the SYSTEM$REFERENCE function.
Each element in the array should be an array containing a tag reference and a tag value. For example:
[ [ 'ENT_REF_TAG_10382726315710_8A8626AE765E2' , 'finance' ], ... ]
operation_modeSpecifies the matching logic to use for the specified tags. You can specify one of the following values:
'UNION': Usage by a user is included in the budget if the user is tagged with any of the specified tag-value pairs. This corresponds to OR logic.'INTERSECTION': Usage by a user is included in the budget only if the user is tagged with all of the specified tag-value pairs. This corresponds to AND logic.
Returns¶
Returns a VARCHAR value that indicates whether or not the tags were successfully set on the budget.
If the tags could not be set on the budget, the function returns an error message.
Access control requirements¶
The following privileges and roles are required to call this method for a custom budget:
ADMIN instance role for the budget instance.
USAGE privilege on the database and schema that contain the budget instance.
USAGE privilege on the database and schema that contain each tag.
APPLYBUDGET privilege on each tag being added.
For more information, see Budgets roles and privileges.
Usage notes¶
You can only set tags on custom budgets.
By default, you can add up to 20 resource tags to the budget. To increase this limit, contact Snowflake Support.
To verify the results of the method, call the GET_BUDGET_SCOPE method.
Snowflake doesn’t start showing usage for the added resources until the budget is refreshed, which can take up to six hours. If you want to view usage sooner, run the REFRESH_USAGE method.
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.
Examples¶
Use the my_budget budget to track all objects that are tagged with either the tag-value combination cost_center = 'sales' or the
tag-value combination team_tag = 'finance'.
CALL budget_db.budget_schema.my_budget!SET_RESOURCE_TAGS(
[
[(SELECT SYSTEM$REFERENCE('TAG', 'cost_mgmt_db.tags.cost_center', 'SESSION', 'APPLYBUDGET')), 'sales'],
[(SELECT SYSTEM$REFERENCE('TAG', 'cost_mgmt_db.tags.team_tag', 'SESSION', 'APPLYBUDGET')), 'finance']
],
'UNION');
Use the my_budget budget to track all objects that are tagged with both cost_center = 'sales' and team_tag = 'finance'.
CALL budget_db.budget_schema.my_budget!SET_RESOURCE_TAGS(
[
[(SELECT SYSTEM$REFERENCE('TAG', 'cost_mgmt_db.tags.cost_center', 'SESSION', 'APPLYBUDGET')), 'sales'],
[(SELECT SYSTEM$REFERENCE('TAG', 'cost_mgmt_db.tags.team_tag', 'SESSION', 'APPLYBUDGET')), 'finance']
],
'INTERSECTION');