Deleting labels
You can delete a label from a dataset, table, or view by:
- Using the Google Cloud console
- Using SQL DDL statements
- Using the bq command-line tool's
bq update
command - Calling the
datasets.patch
ortables.patch
API methods - Using the client libraries
Before you begin
Grant Identity and Access Management (IAM) roles that give users the necessary permissions to perform each task in this document. The permissions required to perform a task (if any) are listed in the "Required permissions" section of the task.
Deleting a dataset label
The following sections specify the permissions and steps for deleting a dataset label.
Required permissions
To delete a dataset label, you need the following IAM permissions:
bigquery.datasets.get
bigquery.datasets.update
Each of the following predefined IAM roles includes the permissions that you need in order to delete a dataset label:
roles/bigquery.dataOwner
roles/bigquery.admin
Additionally, if you have the bigquery.datasets.create
permission, you can delete labels of the datasets that you create.
For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.
Deleting a dataset label
To delete a label from a dataset, choose one of the following options:
Console
In the Google Cloud console, select the dataset.
On the dataset details page, click the pencil icon to the right of Labels.
In the Edit labels dialog:
- For each label you want to delete, click delete (X).
- To save your changes, click Update.
SQL
Use the
ALTER SCHEMA SET OPTIONS
DDL statement
to set the labels on an existing dataset. Setting labels overwrites any
existing labels on the dataset. The following example deletes all labels on
the dataset mydataset
:
In the Google Cloud console, go to the BigQuery page.
In the query editor, enter the following statement:
ALTER SCHEMA mydataset SET OPTIONS (labels = []);
Click
Run.
For more information about how to run queries, see Run an interactive query.
bq
To delete a dataset label, issue the bq update
command with the
clear_label
flag. Repeat the flag to delete multiple labels.
If the dataset is in a project other than your default project, add the
project ID to the dataset in the following format:
project_id:dataset
.
bq update \ --clear_label key \ project_id:dataset
Where:
- key is the key for a label that you want to delete.
- project_id is your project ID.
- dataset is the dataset you're updating.
Examples:
To delete the department:shipping
label from mydataset
, enter the
bq update
command with the --clear_label
flag. mydataset
is in your
default project.
bq update --clear_label department mydataset
To delete the department:shipping
label from mydataset
in
myotherproject
, enter the bq update
command with the --clear_label
flag.
bq update --clear_label department myotherproject:mydataset
To delete multiple labels from a dataset, repeat the clear_label
flag and
specify each label's key. For example, to delete the department:shipping
label and cost_center:logistics
labels from mydataset
in your default
project, enter:
bq update \
--clear_label department \
--clear_label cost_center \
mydataset
For each of these examples, the output looks like the following:
Dataset 'myproject:mydataset' successfully updated.
API
To delete a particular label for an existing dataset, call the
datasets.patch
method and update the labels
property for the dataset resource
by setting the label's key value to null
.
To delete all labels from a dataset, call the
datasets.patch
method and delete the labels
property.
Because the datasets.update
method replaces the entire dataset resource,
the datasets.patch
method is preferred.
Go
Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Go API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Node.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Python API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Deleting a table or view label
You can delete a table or view label in the following ways:
- Using the Google Cloud console
- Using SQL DDL statements
- Using the bq command-line tool's
bq update
command - Calling the
tables.patch
API method- Because views are treated like table resources,
tables.patch
is used to modify both views and tables.
- Because views are treated like table resources,
- Using the client libraries
Required permissions
To delete a table or view label, you need the following IAM permissions:
bigquery.tables.get
bigquery.tables.update
Each of the following predefined IAM roles includes the permissions that you need in order to delete a table or view label:
roles/bigquery.dataEditor
roles/bigquery.dataOwner
roles/bigquery.admin
Additionally, if you have the bigquery.datasets.create
permission, you can delete labels of the tables and views in the datasets that you create.
For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.
Deleting a table or view label
To delete a label from a table or view, choose one of the following options:
Console
In the Google Cloud console, select the dataset.
Click the Details tab, and then click the pencil icon to the right of Labels.
In the Edit labels dialog:
For each label you want to delete, click delete (X).
To save your changes, click Update.
SQL
Use the
ALTER TABLE SET OPTIONS
DDL statement to set the label on an existing table, or the
ALTER VIEW SET OPTIONS
DDL statement
to set the label on an existing view. Setting labels overwrites any
existing labels on the table or view. The following example deletes all
labels from the table mytable
:
In the Google Cloud console, go to the BigQuery page.
In the query editor, enter the following statement:
ALTER TABLE mydataset.mytable SET OPTIONS (labels = []);
Click
Run.
For more information about how to run queries, see Run an interactive query.
bq
To delete a label from a table or view, issue the bq update
command with
the clear_label
flag. Repeat the flag to delete multiple labels.
If the table or view is in a project other than your default project, add
the project ID to the dataset in the following format:
project_id:dataset
.
bq update \ --clear_label key \ project_id:dataset.table_or_view
Where:
- key is the key for a label that you want to delete.
- project_id is your project ID.
- dataset is the dataset you're updating.
- table_or_view is the name of the table or view you're updating.
Examples:
To delete the department:shipping
label from mydataset.mytable
, enter
the bq update
command with the --clear_label
flag. mydataset
is in
your default project.
bq update --clear_label department mydataset.mytable
To delete the department:shipping
label from mydataset.myview
in
myotherproject
, enter the bq update
command with the --clear_label
flag.
bq update --clear_label department myotherproject:mydataset.myview
To delete multiple labels from a table or view, repeat the clear_label
flag and specify each label's key. For example, to delete the
department:shipping
label and cost_center:logistics
label from
mydataset.mytable
in your default project, enter:
bq update \
--clear_label department \
--clear_label cost_center \
mydataset.mytable
For each of these examples, the output looks like the following:
Table 'myproject:mydataset.mytable' successfully updated.
API
To delete a particular label for an existing table or view, call the
tables.patch
method and update the labels
property for the table resource
by setting the label's key value to null
.
To delete all labels from a table or view, call the
tables.patch
method and delete the labels
property.
Because views are treated like table resources, you use the tables.patch
method to modify both views and tables. Also, because the tables.update
method replaces the entire dataset resource, the tables.patch
method is
preferred.
Go
Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Go API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Node.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Python API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Deleting job labels
Currently, deleting a label from an existing job is not supported.
What's next
- Learn how to add labels to BigQuery resources.
- Learn how to view labels on BigQuery resources.
- Learn how to update labels on BigQuery resources.
- Learn how to filter resources using labels.
- Read about Using labels in the Resource Manager documentation.