Deleting labels

This page explains how to remove labels from BigQuery resources.

Overview

A label can be removed from a dataset, table, or view by:

  • Using the Cloud Console or the classic web UI
  • Using the command-line tool's bq update command
  • Calling the datasets.patch or tables.patch API methods
  • Using the client libraries

Required permissions

At a minimum, to remove a dataset label, you must be granted bigquery.datasets.get and bigquery.datasets.update permissions. The following predefined Cloud IAM roles include bigquery.datasets.update and bigquery.datasets.get permissions:

  • bigquery.dataOwner
  • bigquery.admin

In addition, if a user has bigquery.datasets.create permissions, when that user creates a dataset, they are granted bigquery.dataOwner access to it. bigquery.dataOwner access gives the user the ability to remove labels from their datasets and from tables and views in those datasets.

For more information on Cloud IAM roles and permissions in BigQuery, see Predefined roles and permissions.

Deleting a dataset label

To remove a label from a dataset:

Console

  1. In the Cloud Console, select the dataset.

  2. On the dataset details page, click the pencil icon to the right of Labels.

    Label pencil

  3. In the Edit labels dialog:

    • Click the delete icon (X) for each label you want to remove.
    • Click Update to save your changes.

Classic UI

  1. In the web UI, select the dataset.

  2. On the Dataset Details page, to the right of Labels, click Edit.

  3. In the Edit Labels dialog:

    • Click the delete icon (X) for each label you want to remove.
    • Click OK.

      Delete label

CLI

To remove a dataset label, issue the bq update command with the clear_label flag. Repeat the flag to remove 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 remove.
  • project_id is your project ID.
  • dataset is the dataset you're updating.

Examples:

To remove 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 remove 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 remove multiple labels from a dataset, repeat the clear_label flag and specify each label's key. For example, to remove 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 remove 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 remove all labels from a dataset, call the datasets.patch method and remove 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 run this sample, you will need to create (or reuse) a context and
// an instance of the bigquery client.  For example:
// import "cloud.google.com/go/bigquery"
// ctx := context.Background()
// client, err := bigquery.NewClient(ctx, "your-project-id")
ds := client.Dataset(datasetID)
meta, err := ds.Metadata(ctx)
if err != nil {
	return err
}
update := bigquery.DatasetMetadataToUpdate{}
update.DeleteLabel("color")
if _, err := ds.Update(ctx, update, meta.ETag); err != nil {
	return err
}

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 .

# TODO(developer): Import the client library.
# from google.cloud import bigquery

# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()

# TODO(developer): Set dataset_id to the ID of the dataset to fetch.
# dataset_id = "your-project.your_dataset"

dataset = client.get_dataset(dataset_id)  # Make an API request.

# To delete a label from a dataset, set its value to None.
dataset.labels["color"] = None

dataset = client.update_dataset(dataset, ["labels"])  # Make an API request.
print("Labels deleted from {}".format(dataset_id))

Deleting a table or view label

You can remove a table or view label by:

  • Using the Cloud Console or the classic BigQuery web UI
  • Using the 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.
  • Using the client libraries

Required permissions

At a minimum, to remove a table or view label, you must be granted bigquery.tables.update and bigquery.tables.get permissions. The following predefined Cloud IAM roles include bigquery.tables.update and bigquery.tables.get permissions:

  • bigquery.dataEditor
  • bigquery.dataOwner
  • bigquery.admin

In addition, if a user has bigquery.datasets.create permissions, when that user creates a dataset, they are granted bigquery.dataOwner access to it. bigquery.dataOwner access gives the user the ability to remove labels from tables and views in a dataset.

For more information on Cloud IAM roles and permissions in BigQuery, see Predefined roles and permissions.

Deleting a table or view label

To remove a label from a table or view:

Console

  1. In the Cloud Console, select the dataset.

  2. Click the Details tab, and then click the pencil icon to the right of Labels.

    Label pencil

  3. In the Edit labels dialog:

    • Click the delete icon (X) for each label you want to remove.

      Label delete

    • Click Update to save your changes.

Classic UI

  1. In the web UI, select the table or view.

  2. On the Details page, to the right of Labels, click Edit.

  3. In the Edit Labels dialog:

    • Click the delete icon (X) for each label you want to remove.
    • Click OK.

      Delete label

CLI

To remove a label from a table or view, issue the bq update command with the clear_label flag. Repeat the flag to remove 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 remove.
  • 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 remove 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 remove 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 remove multiple labels from a table or view, repeat the clear_label flag and specify each label's key. For example, to remove 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 remove 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 remove all labels from a table or view, call the tables.patch method and remove 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 run this sample, you will need to create (or reuse) a context and
// an instance of the bigquery client.  For example:
// import "cloud.google.com/go/bigquery"
// ctx := context.Background()
// client, err := bigquery.NewClient(ctx, "your-project-id")
tbl := client.Dataset(datasetID).Table(tableID)
meta, err := tbl.Metadata(ctx)
if err != nil {
	return err
}
update := bigquery.TableMetadataToUpdate{}
update.DeleteLabel("color")
if _, err := tbl.Update(ctx, update, meta.ETag); err != nil {
	return err
}

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 .

# from google.cloud import bigquery
# client = bigquery.Client()
# table_ref = client.dataset('my_dataset').table('my_table')
# table = client.get_table(table_ref)  # API request

# This example table starts with one label
assert table.labels == {"color": "green"}
# To delete a label from a table, set its value to None
table.labels["color"] = None

table = client.update_table(table, ["labels"])  # API request

assert table.labels == {}

Deleting job labels

Currently, deleting a label from an existing job is not supported.

What's next

¿Te sirvió esta página? Envíanos tu opinión:

Enviar comentarios sobre…

¿Necesitas ayuda? Visita nuestra página de asistencia.