A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/bigquery/docs/updating-views below:

Manage logical views | BigQuery

Stay organized with collections Save and categorize content based on your preferences.

Manage logical views

This document describes how to manage views in BigQuery. You can manage your BigQuery views in the following ways:

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.

Update a view

After creating a view, you can update the following view properties:

Required permissions

To update a view, you need the following IAM permissions:

Each of the following predefined IAM roles includes the permissions that you need in order to update a view:

Additionally, if you have the bigquery.datasets.create permission, you can update tables and views in the datasets that you create.

To update the view's SQL query, you must also have permissions to query any tables referenced by the view's SQL query.

Note: To update the SQL of an authorized view, or a view in an authorized dataset, you need additional permissions. For more information, see required permissions for authorized views and required permissions for views in authorized datasets.

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

Updating a view's SQL query

You can update the SQL query used to define a view by:

You can change the SQL dialect from legacy SQL to GoogleSQL in the API or bq command-line tool. You cannot update a legacy SQL view to GoogleSQL in the Google Cloud console.

To update a view's SQL query:

Console
  1. In the Explorer panel, expand your project and dataset, then select the view.

  2. Click the Details tab.

  3. Above the Query box, click the Edit query button. Click Open in the dialog that appears.

  4. Edit the SQL query in the Query editor box and then click Save view.

  5. Make sure all the fields are correct in the Save view dialog and then click Save.

bq

Issue the bq update command with the --view flag. To use GoogleSQL or to update the query dialect from legacy SQL to GoogleSQL, include the --use_legacy_sql flag and set it to false.

If your query references external user-defined function resources stored in Cloud Storage or in local files, use the --view_udf_resource flag to specify those resources. The --view_udf_resource flag is not demonstrated here. For more information on using UDFs, see GoogleSQL User-Defined Functions.

If you are updating a view in a project other than your default project, add the project ID to the dataset name in the following format: project_id:dataset.

bq update \
    --use_legacy_sql=false \
    --view_udf_resource=path_to_file \
    --view='query' \
    project_id:dataset.view

Replace the following:

Examples

Enter the following command to update the SQL query for a view named myview in mydataset. mydataset is in your default project. The example query used to update the view queries data from the USA Name Data public dataset.

bq update \
    --use_legacy_sql=false \
    --view \
    'SELECT
      name,
      number
    FROM
      `bigquery-public-data.usa_names.usa_1910_current`
    WHERE
      gender = "M"
    ORDER BY
      number DESC;' \
    mydataset.myview

Enter the following command to update the SQL query for a view named myview in mydataset. mydataset is in myotherproject, not your default project. The example query used to update the view queries data from the USA Name Data public dataset.

bq update \
    --use_legacy_sql=false \
    --view \
    'SELECT
      name,
      number
    FROM
      `bigquery-public-data.usa_names.usa_1910_current`
    WHERE
      gender = "M"
    ORDER BY
      number DESC;' \
    myotherproject:mydataset.myview
API

You can update a view by calling the tables.patch method with a table resource that contains an updated view property. Because the tables.update method replaces the entire table 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.

Note: If you update the datasets referenced by the query of an authorized view, you must authorize the view access to any new underlying datasets. Updating a view's expiration time

You can set a default table expiration time at the dataset level (which affects both tables and views), or you can set a view's expiration time when the view is created. If you set the expiration when the view is created, the dataset's default table expiration is ignored. If you do not set a default table expiration at the dataset level, and you do not set an expiration when the view is created, the view never expires and you must delete the view manually.

At any point after the view is created, you can update the view's expiration time by:

Note: If you set an expiration time that has already passed, the view is deleted immediately.

To update a view's expiration time:

Console
  1. In the navigation pane, select your view.

  2. On the view Details page, click the Details tab.

  3. To the right of View info, click the edit icon (pencil).

  4. In the View info dialog, for View expiration, click Specify date.

  5. In the date picker, enter the expiration date and time and then click Ok.

  6. Click Update. The updated expiration time appears in the View info section.

SQL

Use the ALTER VIEW SET OPTIONS DDL statement:

  1. In the Google Cloud console, go to the BigQuery page.

    Go to BigQuery

  2. In the query editor, enter the following statement:

     ALTER VIEW DATASET_ID.MY_VIEW
     SET OPTIONS (
      expiration_timestamp = TIMESTAMP('NEW_TIMESTAMP'));

    Replace the following:

  3. Click play_circle Run.

For more information about how to run queries, see Run an interactive query.

bq

Issue the bq update command with the --expiration flag. If you are updating a view in a project other than your default project, add the project ID to the dataset name in the following format: project_id:dataset.

bq update \
    --expiration integer \
    project_id:dataset.view

Replace the following::

Examples

Enter the following command to update the expiration time of myview in mydataset to 5 days (432000 seconds). mydataset is in your default project.

bq update \
    --expiration 432000 \
    mydataset.myview

Enter the following command to update the expiration time of myview in mydataset to 5 days (432000 seconds). mydataset is in myotherproject, not your default project.

bq update \
    --expiration 432000 \
    myotherproject:mydataset.myview
API

Call the tables.patch method and use the expirationTime property in the table resource. Because the tables.update method replaces the entire table resource, the tables.patch method is preferred. When you use the REST API, the view's expiration is expressed in milliseconds.

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

Updating a view's expiration is the same process as updating a table's expiration.

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.

Updating a view's description

You can update a view's description by:

To update a view's description:

Console

You cannot add a description when you create a view using the Google Cloud console. After the view is created, you can add a description on the Details page.

  1. In the Explorer panel, expand your project and dataset, then select the view.

  2. Click the Details tab.

  3. Click the pencil icon next to Description.

  4. Enter a description in the dialog box. Click Update to save the new description.

SQL

Use the ALTER VIEW SET OPTIONS DDL statement:

  1. In the Google Cloud console, go to the BigQuery page.

    Go to BigQuery

  2. In the query editor, enter the following statement:

     ALTER VIEW DATASET_ID.MY_VIEW
     SET OPTIONS (
      description = 'NEW_DESCRIPTION');

    Replace the following:

  3. Click play_circle Run.

For more information about how to run queries, see Run an interactive query.

bq

Issue the bq update command with the --description flag. If you are updating a view in a project other than your default project, add the project ID to the dataset name in the following format: [PROJECT_ID]:[DATASET].

bq update \
    --description "description" \
    project_id:dataset.view

Replace the following:

Examples

Enter the following command to change the description of myview in mydatasetto "Description of myview." mydataset is in your default project.

bq update \
    --description "Description of myview" \
    mydataset.myview

Enter the following command to change the description of myview in mydataset to "Description of myview." mydataset is in myotherproject, not your default project.

bq update \
    --description "Description of myview" \
    myotherproject:mydataset.myview
API

Call the tables.patch method and use the description property to update the view's description in the table resource. Because the tables.update method replaces the entire table 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

Updating a view's description is the same process as updating a table's description.

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

Updating a view's description is the same process as updating a table's description.

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.

Copy views

You can copy a view using the Google Cloud console.

You cannot copy a view by using the bq command-line tool, the REST API, or the client libraries, but you can copy a view in the target dataset.

Required permissions

To copy a view in the Google Cloud console, you need IAM permissions on the source and destination datasets.

Each of the following predefined IAM roles includes the permissions that you need in order to copy a view:

Additionally, if you have the bigquery.datasets.create permission, you can copy views in the datasets that you create. You also need access to the destination dataset unless you created it.

Note: bigquery.jobs.create permissions are not required to copy a view. The Google Cloud console does not generate a copy job when you copy a view.

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

Copy a view

To copy a view:

  1. In the Explorer panel, expand your project and dataset, then select the view.

  2. In the details panel, click Copy view.

  3. In the Copy view dialog:

Limits for copy jobs apply. For more information, see Quotas and limits.

Rename a view

Currently, you can rename a view only when you use the Google Cloud console to copy the view. For instructions on renaming a view when you copy it, see Copying a view.

You cannot change the name of an existing view by using the bq command-line tool, the API, or the client libraries. Instead, you must recreate the view with the new name.

Delete views

You can delete a view by:

Currently, using any available method, you can only delete one view at a time.

To automatically delete views after a specified period of time, set the default expiration time at the dataset level or set the expiration time when you create the view.

When you delete an authorized view, it might take up to 24 hours to remove the deleted view from the authorized views list of the source dataset.

Caution: Deleting a view cannot be undone. If you recreate an authorized view with the same name as the deleted view, you must add the new view to the authorized views list of the source dataset.

Deleting a view also deletes any permissions associated with this view. When you recreate a deleted view, you must also manually reconfigure any access permissions previously associated with it.

Note: You cannot recover views directly, but you can recover the view creation statement by searching for the corresponding audit log activity. Required permissions

To delete a view, you need the following IAM permissions:

Each of the following predefined IAM roles includes the permissions that you need in order to delete a view:

Additionally, if you have the bigquery.datasets.create permission, you can delete views in the datasets that you create.

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

Delete a view

To delete a view:

Console
  1. In the Google Cloud console, go to the BigQuery page.

    Go to BigQuery

  2. In the Explorer panel, expand your project and dataset, then select the view.

  3. In the details panel, click Delete view.

  4. Type "delete" in the dialog, and click Delete to confirm.

SQL

Use the DROP VIEW DDL statement:

  1. In the Google Cloud console, go to the BigQuery page.

    Go to BigQuery

  2. In the query editor, enter the following statement:

    DROP VIEW mydataset.myview;

    Replace the following:

  3. Click play_circle Run.

For more information about how to run queries, see Run an interactive query.

bq

Use the bq rm command with the --table flag (or -t shortcut) to delete a view. When you use the bq command-line tool to remove a view, you must confirm the action. You can use the --force flag (or -f shortcut) to skip confirmation.

If the view is in a dataset in a project other than your default project, add the project ID to the dataset name in the following format: project_id:dataset.

bq rm \
-f \
-t \
project_id:dataset.view

Where:

Examples:

You can use the bq command-line tool to run bq commands.

In the Google Cloud console, activate Cloud Shell.

Activate Cloud Shell

Enter the following command to delete myview from mydataset. mydataset is in your default project.

bq rm -t mydataset.myview

Enter the following command to delete myview from mydataset. mydataset is in myotherproject, not your default project.

bq rm -t myotherproject:mydataset.myview

Enter the following command to delete myview from mydataset. mydataset is in your default project. The command uses the -f shortcut to bypass confirmation.

bq rm -f -t mydataset.myview
Note: You can enter the bq ls dataset command to confirm that a view was removed from a dataset. API

Call the tables.delete API method and specify the view to delete using the tableId parameter.

C#

Before trying this sample, follow the C# setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery C# API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

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.

PHP

Before trying this sample, follow the PHP setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery PHP 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.

Ruby

Before trying this sample, follow the Ruby setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Ruby API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Restore a view

You can't restore a deleted view directly, but there are workarounds for certain scenarios:

View security

To control access to views in BigQuery, see Authorized views.

What's next

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4