This document provides an overview of querying data in BigQuery.
Types of queries
After you load your data into BigQuery, you can query the data in your tables. BigQuery supports two types of queries:
- Interactive queries
- Batch queries
By default, BigQuery runs interactive queries, which means that the query is executed as soon as possible.
BigQuery also offers batch queries. BigQuery queues each batch query on your behalf and starts the query as soon as idle resources are available, usually within a few minutes.
Running queries
You can run interactive and batch queries by using the:
- Compose new query option in the Cloud Console
bq
command-line tool'sbq query
command- BigQuery REST API to programmatically call the jobs.query or query-type jobs.insert methods
- BigQuery client libraries
Query jobs
Jobs are actions that BigQuery runs on your behalf to load data, export data, query data, or copy data.
When you use the Cloud Console or the bq
command-line tool to load, export,
query, or copy data, a job resource is automatically created, scheduled, and run. You can also
programmatically create a load, export, query, or copy job. When you create a job
programmatically, BigQuery schedules and runs the job for you.
Because jobs can potentially take a long time to complete, they execute asynchronously and can be polled for their status. Shorter actions, such as listing resources or getting metadata, are not managed by a job resource.
Saving and sharing queries
BigQuery lets you save queries and share queries with others.
When you save a query, it can be private (visible only to you), shared at the project level (visible to project members), or public (anyone can view it). For more information, see saving and sharing queries.
Query pricing
Query pricing refers to the cost of running your SQL commands and user-defined functions. BigQuery charges for queries by using one metric: the number of bytes processed. You are charged for the number of bytes processed whether the data is stored in BigQuery or in an external data source such as Cloud Storage, Google Drive, or Cloud Bigtable.
The first 1 TB of data processed per month is free of charge (per billing account). Beyond your first 1 TB of data processed in a month, you are charged according to the On-demand pricing model.
BigQuery also offers Flat-rate pricing for high-volume or enterprise customers who prefer a stable monthly cost for queries.
Quotas and query cost controls
BigQuery enforces project-level quotas on running queries. For information on query quotas, see Quotas and limits.
To control query costs, BigQuery provides several options including custom quotas and billing alerts. For more information, see Creating custom cost controls.
You can also use audit logs to analyze query behavior and Cloud Monitoring to view query metrics.
Next steps
- To learn about the Standard SQL syntax used for querying data in BigQuery, see Query syntax in Standard SQL.
- For information about querying data in partitioned tables, see Querying partitioned tables.
- To learn how to run queries, see Running interactive and batch queries.
- For information about managing query output, see Writing query results.
- To learn how to use the query cache, see Using cached query results.
- For information about running queries that are constructed using user input, see Running parameterized queries.
- To learn how to save and share queries, see Saving and sharing queries.
- For information about reading the query explain plan, see Using the query plan explanation.
- To learn how to schedule a recurring query, see Scheduling queries.