- HTTP request
- Path parameters
- Request body
- Response body
- Authorization scopes
- QueryRequest
- JobCreationMode
- Try it!
Runs a BigQuery SQL query synchronously and returns query results if the query completes within a specified timeout.
HTTP request
POST https://bigquery.googleapis.com/bigquery/v2/projects/{projectId}/queries
The URL uses gRPC Transcoding syntax.
Path parameters
Parameters | |
---|---|
project |
Required. Project ID of the query request. |
Request body
The request body contains an instance of QueryRequest
.
Response body
If successful, the response body contains data with the following structure:
JSON representation |
---|
{ "kind": string, "schema": { object ( |
Fields | |
---|---|
kind |
The resource type. |
schema |
The schema of the results. Present only when the query completes successfully. |
job |
Reference to the Job that was created to run the query. This field will be present even if the original request timed out, in which case jobs.getQueryResults can be used to read the results once the query has completed. Since this API only returns the first page of results, subsequent pages can be fetched via the same mechanism (jobs.getQueryResults). If jobCreationMode was set to |
job |
Optional. The reason why a Job was created. Only relevant when a jobReference is present in the response. If jobReference is not present it will always be unset. Preview |
query |
Auto-generated ID for the query. Preview |
total |
The total number of rows in the complete query result set, which can be more than the number of rows in this single page of results. |
page |
A token used for paging results. A non-empty token indicates that additional results are available. To see additional results, query the |
rows[] |
An object with as many results as can be contained within the maximum permitted reply size. To get any additional rows, you can call jobs.getQueryResults and specify the jobReference returned above. |
total |
The total number of bytes processed for this query. If this query was a dry run, this is the number of bytes that would be processed if the query were run. |
job |
Whether the query has completed or not. If rows or totalRows are present, this will always be true. If this is false, totalRows will not be available. |
errors[] |
Output only. The first errors or warnings encountered during the running of the job. The final message includes the number of errors that caused the process to stop. Errors here do not necessarily mean that the job has completed or was unsuccessful. For more information about error messages, see Error messages. |
cache |
Whether the query result was fetched from the query cache. |
num |
Output only. The number of rows affected by a DML statement. Present only for DML statements INSERT, UPDATE or DELETE. |
session |
Output only. Information of the session if this job is part of one. |
dml |
Output only. Detailed statistics for DML statements INSERT, UPDATE, DELETE, MERGE or TRUNCATE. |
Authorization scopes
Requires one of the following OAuth scopes:
https://www.googleapis.com/auth/bigquery
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/bigquery.readonly
https://www.googleapis.com/auth/cloud-platform.read-only
For more information, see the Authentication Overview.
QueryRequest
Describes the format of the jobs.query request.
JSON representation |
---|
{ "kind": string, "query": string, "maxResults": integer, "defaultDataset": { object ( |
Fields | |
---|---|
kind |
The resource type of the request. |
query |
Required. A query string to execute, using Google Standard SQL or legacy SQL syntax. Example: "SELECT COUNT(f1) FROM myProjectId.myDatasetId.myTableId". |
max |
Optional. The maximum number of rows of data to return per page of results. Setting this flag to a small value such as 1000 and then paging through results might improve reliability when the query result set is large. In addition to this limit, responses are also limited to 10 MB. By default, there is no maximum row count, and only the byte limit applies. |
default |
Optional. Specifies the default datasetId and projectId to assume for any unqualified table names in the query. If not set, all table names in the query string must be qualified in the format 'datasetId.tableId'. |
timeout |
Optional. Optional: Specifies the maximum amount of time, in milliseconds, that the client is willing to wait for the query to complete. By default, this limit is 10 seconds (10,000 milliseconds). If the query is complete, the jobComplete field in the response is true. If the query has not yet completed, jobComplete is false. You can request a longer timeout period in the timeoutMs field. However, the call is not guaranteed to wait for the specified timeout; it typically returns after around 200 seconds (200,000 milliseconds), even if the query is not complete. If jobComplete is false, you can continue to wait for the query to complete by calling the getQueryResults method until the jobComplete field in the getQueryResults response is true. |
dry |
Optional. If set to true, BigQuery doesn't run the job. Instead, if the query is valid, BigQuery returns statistics about the job such as how many bytes would be processed. If the query is invalid, an error returns. The default value is false. |
preserveNulls |
This property is deprecated. |
use |
Optional. Whether to look for the result in the query cache. The query cache is a best-effort cache that will be flushed whenever tables in the query are modified. The default value is true. |
use |
Specifies whether to use BigQuery's legacy SQL dialect for this query. The default value is true. If set to false, the query will use BigQuery's GoogleSQL: https://cloud.google.com/bigquery/sql-reference/ When useLegacySql is set to false, the value of flattenResults is ignored; query will be run as if flattenResults is false. |
parameter |
GoogleSQL only. Set to POSITIONAL to use positional (?) query parameters or to NAMED to use named (@myparam) query parameters in this query. |
query |
jobs.query parameters for GoogleSQL queries. |
location |
The geographic location where the job should run. See details at https://cloud.google.com/bigquery/docs/locations#specifying_your_location. |
format |
Optional. Output format adjustments. |
connection |
Optional. Connection properties which can modify the query behavior. |
labels |
Optional. The labels associated with this query. Labels can be used to organize and group query jobs. Label keys and values can be no longer than 63 characters, can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label keys must start with a letter and each label in the list must have a different key. |
maximum |
Optional. Limits the bytes billed for this query. Queries with bytes billed above this limit will fail (without incurring a charge). If unspecified, the project default is used. |
request |
Optional. A unique user provided identifier to ensure idempotent behavior for queries. Note that this is different from the jobId. It has the following properties:
|
create |
Optional. If true, creates a new session using a randomly generated sessionId. If false, runs query with an existing sessionId passed in ConnectionProperty, otherwise runs query in non-session mode. The session location will be set to QueryRequest.location if it is present, otherwise it's set to the default location based on existing routing logic. |
job |
Optional. If not set, jobs are always required. If set, the query request will follow the behavior described JobCreationMode. Preview |
JobCreationMode
Job Creation Mode provides different options on job creation.
Enums | |
---|---|
JOB_CREATION_MODE_UNSPECIFIED |
If unspecified JOB_CREATION_REQUIRED is the default. |
JOB_CREATION_REQUIRED |
Default. Job creation is always required. |
JOB_CREATION_OPTIONAL |
Job creation is optional. Returning immediate results is prioritized. BigQuery will automatically determine if a Job needs to be created. The conditions under which BigQuery can decide to not create a Job are subject to change. If Job creation is required, JOB_CREATION_REQUIRED mode should be used, which is the default. |