First, create a new query in the BigQuery web UI or using the bq command-line tool.
After running the query, click on the “Save” button located at the top-right corner of the query results tab.
Enter a name for the saved query and select a location to save it to. You can choose to save it to a specific project or dataset.
Choose the access level for the saved query, either “private” or “shared”.
Click on “Save” to save the query.
If you want to access the saved query later, go to the “Queries” tab in the BigQuery web UI, and find the query in the location you saved it to.
If you are using the command line tool, you can list all saved queries by running bq ls -j --all command
To run the saved query, use the bq query command followed by the name of the saved query.
How to save a bigquery query with Sherloq
An alternative way to save queries easily is through the use of the Sherloq chrome extension. This extension allows you to save and organize queries directly from the BigQuery web UI with just a few clicks. Some of the advantages of using Sherloq over the built-in functionality in BigQuery include:
Easily sharing queries among your team: Sherloq allows you to share your saved queries with specific individuals or groups, making it easy to collaborate with others.
Organized by folder: Sherloq allows you to organize your saved queries into different folders, making it easy to find and access the queries you need.
Version control and editing: Sherloq provides version control and the ability to edit your queries directly within the extension, so you can keep track of changes and easily revert to previous versions if needed.