Method: jobs.query

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
projectId

string

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 (TableSchema)
  },
  "jobReference": {
    object (JobReference)
  },
  "totalRows": string,
  "pageToken": string,
  "rows": [
    {
      object
    }
  ],
  "totalBytesProcessed": string,
  "jobComplete": boolean,
  "errors": [
    {
      object (ErrorProto)
    }
  ],
  "cacheHit": boolean,
  "numDmlAffectedRows": string,
  "sessionInfo": {
    object (SessionInfo)
  },
  "dmlStats": {
    object (DmlStats)
  }
}
Fields
kind

string

The resource type.

schema

object (TableSchema)

The schema of the results. Present only when the query completes successfully.

jobReference

object (JobReference)

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).

totalRows

string (UInt64Value format)

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.

pageToken

string

A token used for paging results. A non-empty token indicates that additional results are available. To see additional results, query the jobs.getQueryResults method. For more information, see Paging through table data.

rows[]

object (Struct format)

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.

totalBytesProcessed

string (Int64Value format)

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.

jobComplete

boolean

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[]

object (ErrorProto)

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.

cacheHit

boolean

Whether the query result was fetched from the query cache.

numDmlAffectedRows

string (Int64Value format)

Output only. The number of rows affected by a DML statement. Present only for DML statements INSERT, UPDATE or DELETE.

sessionInfo

object (SessionInfo)

Output only. Information of the session if this job is part of one.

dmlStats

object (DmlStats)

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

JSON representation
{
  "kind": string,
  "query": string,
  "maxResults": integer,
  "defaultDataset": {
    object (DatasetReference)
  },
  "timeoutMs": integer,
  "dryRun": boolean,
  "preserveNulls": boolean,
  "useQueryCache": boolean,
  "useLegacySql": boolean,
  "parameterMode": string,
  "queryParameters": [
    {
      object (QueryParameter)
    }
  ],
  "location": string,
  "formatOptions": {
    object (DataFormatOptions)
  },
  "connectionProperties": [
    {
      object (ConnectionProperty)
    }
  ],
  "labels": {
    string: string,
    ...
  },
  "maximumBytesBilled": string,
  "requestId": string,
  "createSession": boolean
}