Manage saved queries

This document describes how to manage saved queries and classic saved queries.

Saved queries

Use the following sections to learn how to manage saved queries. Saved queries are BigQuery Studio code assets powered by Dataform.

Required permissions

To manage saved queries, you need the following Identity and Access Management (IAM) roles:

For more information about BigQuery IAM, see Access control with IAM.

Grant access to saved queries

To grant other users access to a saved query, add those users to an appropriate IAM role.

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Find the saved query that you want to grant access to.

  3. Click View actions next to the saved query, and then click Share > Manage Permissions.

  4. In the Manage permissions pane, click Add user/group.

  5. In the New principals field, enter a principal.

  6. In the Role list, select one of the following roles:

  7. Optional: To view a complete list of roles and advanced sharing settings, click Advanced sharing.

  8. Click Save.

  9. To return to the saved query info, click Close.

Share saved queries

You can share a saved query with other users by generating and sharing a link to the saved query. Before users can see the saved query you share, you must first grant them access to the saved query.

To run a shared query, users must have access to the data that the query accesses. For more information, see Grant access to a dataset.

If you plan to share a saved query, consider including a comment in the query that describes its purpose.

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, expand the Shared queries folder. Find the saved query that you want to share.

  3. Click View actions next to the query and then click Share > Copy link.

  4. Share the link with other users.

View all saved queries

To view a list of all saved queries in your project, do the following:

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

    Go to BigQuery

  2. In the Explorer pane, click View actions next to Queries, and then do one of the following:

  • To open the list in the current tab, click Show all.
  • To open the list in a new tab, click Show all in > New tab.
  • To open the list in a split tab, click Show all in > Split tab.

View saved query metadata

To view saved query metadata, follow these steps:

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Click the name of the saved query you want to view metadata for.

  3. Look at the Summary pane to see information about the saved query such as the region it uses and the date it was last modified.

Work with saved query versions

Use the following sections to learn how to view, compare, and restore versions of a saved query.

View saved query versions

To view saved query versions, follow these steps:

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Click the name of the saved query you want to view activity for.

  3. Click the Activity tab to see a list of the saved query versions in descending order by date.

Compare saved query versions

To compare saved query versions, follow these steps:

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Click the name of the saved query you want to compare version information for.

  3. In the Activity tab, click View actions next to a saved query version and then click Compare. The comparison pane opens, comparing the saved query version you selected with the current saved query version.

  4. Optional: To compare the versions inline instead of in separate panes, click Compare and then click Inline.

Restore a saved query version

Use one of the following options to restore a saved query version. Restoring from the comparison pane lets you to compare the previous version of the saved query to the current version before choosing whether to restore it.

Activity pane

  1. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Click the name of the saved query you want to restore a previous version of.
  2. Select the Activity pane.
  3. Click View actions next to the version of the saved query that you want to restore and then click Restore.
  4. Click Confirm to confirm the action.

Comparison pane

  1. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Click the name of the saved query you want to restore a previous version of.
  2. Select the Activity pane.
  3. Click View actions next to a saved query version and then click Compare. The comparison pane opens, comparing the saved query version you selected with the most recent saved query version.
  4. If you want to restore the previous saved query version after comparison, click Restore.
  5. Click Confirm to confirm the action.

Download saved queries

To download a saved query, follow these steps:

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Click the name of a saved query to open it.

  3. Click Download.

Delete saved queries

To delete a saved query, follow these steps:

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the Queries folder, and if necessary, the Shared queries folder. Find the saved query you want to delete.

  3. Click View actions next to the saved query and then click Delete.

  4. To confirm deletion, type delete in the dialog.

  5. Click Delete.

Classic saved queries

Use the following sections to learn how to manage classic saved queries.

Share classic saved queries

You can share classic saved queries that you have given project or public visibility. Project visibility allows principals with the required permissions to view, update, or delete the query. Public visibility allows anyone with the query link to view but not update or delete the query.

You share a classic saved query with other users by generating and sharing a link to the classic saved query.

To run a classic shared query, users must have access to the data that the query accesses. For more information, see Grant access to a dataset.

If you are plan to share a classic saved query, consider including a comment in the query that describes its purpose.

  1. In the Explorer pane, expand your project and the (Classic) Queries folder, and then find the classic saved query you want to share.
  2. Click View actions next to the query and then click Get link.
  3. Share the link with the users you want to grant access to the query.

Migrate classic saved queries

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the (Classic) Queries folder, and if necessary, the Project queries folder.

  3. Click the name of a classic saved query to open it.

  4. Click Save Query (Classic) > Save query as....

  5. In the Save query dialog, type a name and choose the location for the query.

  6. Click Save.

Delete classic saved queries

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

    Go to BigQuery

  2. In the Explorer pane, expand your project and the (Classic) Queries folder, and if necessary, the Project queries folder.

  3. Find the classic saved query you want to delete.

  4. Click View actions next to the query and then click Delete.

  5. To confirm deletion, type delete in the dialog.

  6. Click Delete.