Saving and Sharing Queries

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.

Saving queries

To save a query in BigQuery:

  1. Go to the BigQuery web UI.
    Go to the BigQuery web UI

  2. Click the Compose query button.

  3. Enter a BigQuery SQL query in the New Query text area. For example, you can use the example from the Web UI Quickstart.

    SELECT
     weight_pounds, state, year, gestation_weeks
    FROM
     publicdata:samples.natality
    ORDER BY weight_pounds DESC LIMIT 10;
    
  4. Click the Save Query button to open the Save Query dialog box.

  5. In the Save Query dialog box, enter a name for your saved query; leave the Visibility set to Private (Visible only to you); then click OK.

    Save Query Dialog Box

  6. To view your saved query, ensure that Query History is selected in the left navigation and click on Saved Queries in the Queries section.

    Save Queries List

Modifying queries

If you have write permissions on a query, you can modify it:

  1. Load the query into the query editing window by clicking the Edit Query button.

    Edit query button

  2. Modify the query.

  3. Click the Save Query button to open the Save Query dialog box.

  4. In the Save Query dialog box, leave the name unchanged and click OK.

Sharing queries

To share a query, set its visibility to Project or Public when you save the query.

  • Project visibility makes the query available to other project members.

    • Project members with OWNER/WRITER permissions have read-write access.
    • Project members with READ permissions have read access.
  • Public visibility makes the query viewable, but not editable, to anyone with the link.

When you share a query, consider including a comment that describes the query as shown in the example that follows.

Sharing queries with project members

To share a query with another member of your project:

  1. Go to the BigQuery web UI.
    Go to the BigQuery web UI

  2. Click the Compose query button.

  3. Enter a BigQuery SQL query in the New Query text area. For example, you can use the example from the Web UI Quickstart.

    # Find highest birth weights
    SELECT
     weight_pounds, state, year, gestation_weeks
    FROM
     publicdata:samples.natality
    ORDER BY weight_pounds DESC LIMIT 10;
    
  4. Click the Save Query button to open the Save Query dialog box.

  5. In the Save Query dialog box, enter a name for your saved query; set the Visibility set to Project (Project members can view and edit); then click OK.

    Share Query Project

  6. To view your saved query, ensure that Query History is selected in the left navigation and click on Project Queries in the Queries section.

    Project Queries List

  7. Click on the name of your saved project query to expand the window.

    Project query expanded

  8. Click on the Share Link button to access the shareable link and copy the link to the clipboard.

    Project query share link

    Alternatively, you can access the link via the link icon above the New Query text area.

    Query Link icon

  9. Share the link with another member of your team.

Sharing queries with the public

To share a query with anyone:

  1. Go to the BigQuery web UI.
    Go to the BigQuery web UI

  2. Click the Compose query button.

  3. Enter a BigQuery SQL query in the New Query text area. For example, you can use the example from the Web UI Quickstart.

    # Find highest birth weights
    SELECT
     weight_pounds, state, year, gestation_weeks
    FROM
     publicdata:samples.natality
    ORDER BY weight_pounds DESC LIMIT 10;
    
  4. Click the Save Query button to open the Save Query dialog box.

  5. In the Save Query dialog box, enter a name for your saved query; set the Visibility set to Public (Anyone with the link can view, but not edit); then click OK.

    Share Query Public

  6. To view your saved query, ensure that Query History is selected in the left navigation and click on Saved Queries in the Queries section.

    Saved Public Queries List

  7. Click on the name of your saved public query to expand the window.

    Public query expanded

  8. Click on the Share Link button to access the shareable link and copy the link to the clipboard.

    Public query share link

    Alternatively, you can access the link via the link icon above the New Query text area.

    Public Query Link icon

  9. Share the link with another member of your team.

Send feedback about...

BigQuery Documentation