This page describes how to save and share queries. Queries that are saved or shared contain only the query itself, which means that:
A shared query provides the query text only. You still need to have appropriate access to query the data. One advantage of saving only the query text is that you can share a query that is incomplete, even if it isn't a valid query, and use it as a template that other users can complete or customize.
The only query option retained by a saved query is the "SQL Version", which governs whether the query uses legacy SQL or standard SQL.
There are 3 types of saved queries:
- Private: Private saved queries are visible only to the user who creates them.
- Project-level: Project-level saved queries are visible to members of the pre-defined BigQuery Cloud IAM roles with the required permissions.
- Public: Public saved queries are visible to anyone with a link to the query.
Permissions
The following Cloud IAM permissions are required to create, view, update, and delete saved queries:
- Private saved queries:
- Creating private saved queries requires no special permissions. You can save a private query in any project, but only you can view, update, or delete the query.
- Project-level saved queries:
- Creating a project-level saved query requires
bigquery.savedqueries.create
permissions. Thebigquery.admin
predefined role includesbigquery.savedqueries.create
permissions. - Viewing a project-level saved query requires
bigquery.savedqueries.get
andbigquery.savedqueries.list
permissions. Thebigquery.admin
andbigquery.user
predefined roles includebigquery.savedqueries.get
andbigquery.savedqueries.list
permissions. - Updating a project-level saved query requires
bigquery.savedqueries.update
permissions. Thebigquery.admin
predefined role includesbigquery.savedqueries.update
permissions. - Deleting a project-level saved query requires
bigquery.savedqueries.delete
permissions. Thebigquery.admin
predefined role includesbigquery.savedqueries.delete
permissions.
- Creating a project-level saved query requires
- Public saved queries:
- Creating public queries requires no special permissions. You can save a public query in any project, but only you can update or delete the query. Anyone with the link can view a public saved query.
For more information on IAM roles in BigQuery, see Predefined roles and permissions.
Creating a private saved query
When you save a query and set the visibility to Private, the query can be viewed, updated, or deleted only by you.
To create a private shared query:
Console
Open the BigQuery web UI in the Cloud Console.
Go to the Cloud ConsoleClick Compose new query.
Enter a valid SQL query in the Query editor text area. For example, you can use the query from the web UI quickstart.
# Find highest birth weights SELECT weight_pounds, state, year, gestation_weeks FROM `bigquery-public-data.samples.natality` ORDER BY weight_pounds DESC LIMIT 10
Click Save query.
In the Save query dialog box, enter a name for your query, set the Visibility to Personal (editable only by you), and then click Save.
To view your saved query, click Saved queries. The Personal queries page should be open by default.
Click the name of your saved query to expand it.
Click Share query URL to access the shareable link and to copy the link to the clipboard. Alternatively, you can access the link via the Link sharing button icon above the Query editor text area.
Share the link with another member of your team.
Classic UI
Go to the BigQuery web UI.
Go to the BigQuery web UIClick Compose query.
Enter a SQL query in the New Query text area. For example, you can use the query from the classic web UI quickstart.
#standardSQL SELECT weight_pounds, state, year, gestation_weeks FROM `bigquery-public-data.samples.natality` ORDER BY weight_pounds DESC LIMIT 10
Click Save Query to open the Save Query dialog box.
In the Save Query dialog box, enter a name for your saved query, leave the Visibility set to Private (Visible only to you), and then click OK.
To view your saved query, ensure that Query History is selected in the left navigation and click Saved Queries in the Queries section.
Sharing a saved query
To share a query, set the visibility to Project or Public when you save the query. Project visibility allows members of the pre-defined BigQuery Cloud IAM roles 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. To run the query, users must have access to the data that is accessed by the query. For more information, see Controlling access to datasets.
When you share a query, consider including a comment that describes the query as shown in the example that follows.
Creating a project-level saved query
To share a query with another member of your project:
Console
Open the BigQuery web UI in the Cloud Console.
Go to the Cloud ConsoleClick Compose new query.
Enter a valid BigQuery SQL query in the Query editor text area. For example, you can use the query from the web UI quickstart.
# Find highest birth weights SELECT weight_pounds, state, year, gestation_weeks FROM `bigquery-public-data.samples.natality` ORDER BY weight_pounds DESC LIMIT 10
Click Save query.
In the Save query dialog box, enter a name for your query, set the Visibility to Project (editable by project members), and then click Save.
To view your saved query, click Saved queries in the left navigation pane and click Project queries.
Click the name of your saved query to expand it.
Click Share query URL to access the shareable link and to copy the link to the clipboard. Alternatively, you can access the link via the Link sharing button icon above the Query editor text area.
Share the link with another member of your team.
Classic UI
Go to the BigQuery web UI.
Go to the BigQuery web UIClick Compose Query.
Enter a SQL query in the New Query text area. For example, you can use the query from the classic web UI quickstart.
#standardSQL # Find highest birth weights SELECT weight_pounds, state, year, gestation_weeks FROM `bigquery-public-data.samples.natality` ORDER BY weight_pounds DESC LIMIT 10
Click Save Query to open the Save Query dialog box.
In the Save Query dialog box, enter a name for your saved query, set the Visibility to Project (Project members can view and edit), and then click OK.
To view your saved query, ensure that Query History is selected in the left navigation and click Project Queries in the Queries section.
Click the name of your saved query to expand it.
Click Share Link to access the shareable link and to copy the link to the clipboard.
Alternatively, you can access the link via the link icon above the New Query text area.
Share the link with another member of your team.
Creating a public saved query
To share a query with anyone:
Console
Currently it is not possible to create a public saved query using the Cloud Console.
Classic UI
Go to the BigQuery web UI.
Go to the BigQuery web UIClick Compose Query.
Enter a SQL query in the New Query text area. For example, you can use the query from the classic web UI quickstart.
#standardSQL # Find highest birth weights SELECT weight_pounds, state, year, gestation_weeks FROM `bigquery-public-data.samples.natality` ORDER BY weight_pounds DESC LIMIT 10
Click Save Query to open the Save Query dialog box.
In the Save Query dialog box, enter a name for your saved query, set the Visibility to Public (Anyone with the link can view, but not edit), and then click OK.
To view your saved query, ensure that Query History is selected in the left navigation and click Saved Queries in the Queries section.
Click the name of your saved public query to expand it.
Click Share Link to access the shareable link and to copy the link to the clipboard.
Alternatively, you can access the link via the link icon above the New Query text area.
Share the link.
Updating saved queries
To update a saved query:
Console
Open the BigQuery web UI in the Cloud Console.
Go to the Cloud ConsoleClick Saved queries in the left navigation, and click Personal queries (to edit a private query) or Project Queries (to edit a project-level query). Click on your query to expand it.
To the right of the query, click Open query in editor.
Modify the query.
Click Save query to update the query without changing the name. If you want to change the name, click the down arrow next to Save query and select Save as, making updates in the dialog box as necessary.
Classic UI
Go to the BigQuery web UI.
Go to the BigQuery web UIClick Query History in the left navigation and in the Queries section, click Saved Queries (to edit a private query) or Project Queries (to edit a project-level or public query).
To the right of the query, click Edit Query.
Modify the query.
Click Save Query to open the Save Query dialog box.
In the Save Query dialog box, leave the name unchanged and click OK.
Deleting saved queries
To delete a saved query:
Console
Open the BigQuery web UI in the Cloud Console.
Go to the Cloud ConsoleClick Saved queries in the left navigation, and click Personal queries (to delete a private query) or Project Queries (to delete a project-level query). Click on your query to expand it.
Click Delete to the right of the query.
When prompted, click Delete to confirm.
Classic UI
Go to the BigQuery web UI.
Go to the BigQuery web UIClick Query History in the left navigation.
To the right of the query, click the Delete saved query button (X).
When prompted, click OK to confirm.