jobs

POST /projects/{projectsId}/queries

Changed on

Runs a BigQuery SQL query synchronously and returns query results if the query completes within a specified timeout. # IAM Permissions Requires the bigquery.jobs.create permission on the project resource. Data-level permissions are highly dependent on the SQL statement being executed. While standard queries require data access (such as bigquery.tables.getData), complex operations like DDL or DCL may require permissions to manage reservations, IAM policies, or project settings.

Request

  • Base URL
    https://bigquery.googleapis.com/bigquery/v2
  • Auth
    • OAuth 2 and OAuth 2
      Implicit: https://accounts.google.com/o/oauth2/auth
      Scopes: https://www.googleapis.com/auth/bigquery
      Authorization code: https://accounts.google.com/o/oauth2/auth
      Token URL: https://accounts.google.com/o/oauth2/token scopes: https://www.googleapis.com/auth/bigquery
    • or OAuth 2 and OAuth 2
      Implicit: https://accounts.google.com/o/oauth2/auth
      Scopes: https://www.googleapis.com/auth/cloud-platform
      Authorization code: https://accounts.google.com/o/oauth2/auth
      Token URL: https://accounts.google.com/o/oauth2/token scopes: https://www.googleapis.com/auth/cloud-platform
    • or OAuth 2 and OAuth 2
      Implicit: https://accounts.google.com/o/oauth2/auth
      Scopes: https://www.googleapis.com/auth/cloud-platform.read-only
      Authorization code: https://accounts.google.com/o/oauth2/auth
      Token URL: https://accounts.google.com/o/oauth2/token scopes: https://www.googleapis.com/auth/cloud-platform.read-only

Path parameters

projectsIdstring required

Request body

continuousboolean

[Optional] Specifies whether the query should be executed as a continuous query. The default value is false.

createSessionboolean

Optional. If true, creates a new session using a randomly generated session_id. If false, runs query with an existing session_id 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.

dryRunboolean

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.

jobCreationMode'JOB_CREATION_MODE_UNSPECIFIED' | 'JOB_CREATION_REQUIRED' | 'JOB_CREATION_OPTIONAL'

Optional. If not set, jobs are always required. If set, the query request will follow the behavior described JobCreationMode.

jobTimeoutMsstring int64

Optional. Job timeout in milliseconds. If this time limit is exceeded, BigQuery will attempt to stop a longer job, but may not always succeed in canceling it before the job completes. For example, a job that takes more than 60 seconds to complete has a better chance of being stopped than a job that takes 10 seconds to complete. This timeout applies to the query even if a job does not need to be created.

kindstring

The resource type of the request.

labelsobject

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.

locationstring

The geographic location where the job should run. For more information, see how to specify locations.

maxResultsinteger

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.

maxSlotsinteger

Optional. A target limit on the rate of slot consumption by this query. If set to a value > 0, BigQuery will attempt to limit the rate of slot consumption by this query to keep it below the configured limit, even if the query is eligible for more slots based on fair scheduling. The unused slots will be available for other jobs and queries to use. Note: This feature is not yet generally available.

maximumBytesBilledstring int64

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.

parameterModestring

GoogleSQL only. Set to POSITIONAL to use positional (?) query parameters or to NAMED to use named (@myparam) query parameters in this query.

preserveNullsboolean

This property is deprecated.

querystring

Required. A query string to execute, using Google Standard SQL or legacy SQL syntax. Example: "SELECT COUNT(f1) FROM myProjectId.myDatasetId.myTableId".

queryResultsFormat'QUERY_RESULTS_FORMAT_UNSPECIFIED' | 'STRUCT_ENCODING' | 'ARROW'

Optional. The query results format. If the value is anything other than STRUCT_ENCODING or unspecified: * The schema of the results will be provided in QueryResponse.results_schema field. * The results of the first page will be provided in QueryResponse.results field. * The QueryResponse.rows will not be populated. * The QueryResponse.schema for QueryResponse.rows will also not be populated since it is the schema of the QueryResponse.rows. This feature is not yet available.

requestIdstring

Optional. A unique user provided identifier to ensure idempotent behavior for queries. Note that this is different from the job_id. It has the following properties: 1. It is case-sensitive, limited to up to 36 ASCII characters. A UUID is recommended. 2. Read only queries can ignore this token since they are nullipotent by definition. 3. For the purposes of idempotency ensured by the request_id, a request is considered duplicate of another only if they have the same request_id and are actually duplicates. When determining whether a request is a duplicate of another request, all parameters in the request that may affect the result are considered. For example, query, connection_properties, query_parameters, use_legacy_sql are parameters that affect the result and are considered when determining whether a request is a duplicate, but properties like timeout_ms don't affect the result and are thus not considered. Dry run query requests are never considered duplicate of another request. 4. When a duplicate mutating query request is detected, it returns: a. the results of the mutation if it completes successfully within the timeout. b. the running operation if it is still in progress at the end of the timeout. 5. Its lifetime is limited to 15 minutes. In other words, if two requests are sent with the same request_id, but more than 15 minutes apart, idempotency is not guaranteed.

reservationstring

Optional. The reservation that jobs.query request would use. User can specify a reservation to execute the job.query. The expected format is projects/{project}/locations/{location}/reservations/{reservation}. Forces the query to use on-demand billing when set to none. This requires the project or organization to have reservation_override_mode set to ALLOW_ANY_OVERRIDE.

timeoutMsinteger

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.

useLegacySqlboolean

Specifies whether to use BigQuery's legacy SQL dialect for this query. The default value is true. If set to false, the query uses BigQuery's GoogleSQL. When useLegacySql is set to false, the value of flattenResults is ignored; query will be run as if flattenResults is false.

useQueryCacheboolean

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.

writeIncrementalResultsboolean

Optional. This is only supported for SELECT query. If set, the query is allowed to write results incrementally to the temporary result table. This may incur a performance penalty. This option cannot be used with Legacy SQL. This feature is not yet available.

Response

Successful response

cacheHitboolean

Whether the query result was fetched from the query cache.

creationTimestring int64

Output only. Creation time of this query, in milliseconds since the epoch. This field will be present on all queries.

endTimestring int64

Output only. End time of this query, in milliseconds since the epoch. This field will be present whenever a query job is in the DONE state.

jobCompleteboolean

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.

kindstring

The resource type.

locationstring

Output only. The geographic location of the query. For more information about BigQuery locations, see: https://cloud.google.com/bigquery/docs/locations

numDmlAffectedRowsstring int64

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

pageRowCountstring int64

Output only. The number of rows out of total_rows returned in this response. This feature is not yet available.

pageTokenstring

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.

queryIdstring

Auto-generated ID for the query.

startTimestring int64

Output only. Start time of this query, in milliseconds since the epoch. This field will be present when the query job transitions from the PENDING state to either RUNNING or DONE.

statementTypestring

Output only. The type of query statement, if valid. Possible values: * SELECT: SELECT statement. * ASSERT: ASSERT statement. * INSERT: INSERT statement. * UPDATE: UPDATE statement. * DELETE: DELETE statement. * MERGE: MERGE statement. * TRUNCATE_TABLE: TRUNCATE TABLE statement. * CREATE_TABLE: CREATE TABLE statement, without AS SELECT. * CREATE_TABLE_AS_SELECT: CREATE TABLE AS SELECT statement. * CREATE_VIEW: CREATE VIEW statement. * CREATE_MODEL: CREATE MODEL statement. * CREATE_MATERIALIZED_VIEW: CREATE MATERIALIZED VIEW statement. * CREATE_FUNCTION: CREATE FUNCTION statement. * CREATE_TABLE_FUNCTION: CREATE TABLE FUNCTION statement. * CREATE_PROCEDURE: CREATE PROCEDURE statement. * CREATE_ROW_ACCESS_POLICY: CREATE ROW ACCESS POLICY statement. * CREATE_SCHEMA: CREATE SCHEMA statement. * CREATE_EXTERNAL_SCHEMA: CREATE EXTERNAL SCHEMA statement. * CREATE_EXTERNAL_TABLE: CREATE EXTERNAL TABLE statement. * CREATE_SNAPSHOT_TABLE: CREATE SNAPSHOT TABLE statement. * CREATE_SEARCH_INDEX: CREATE SEARCH INDEX statement. * CREATE_VECTOR_INDEX: CREATE VECTOR INDEX statement. * CREATE_CONNECTION: CREATE CONNECTION statement. * CREATE_DATA_POLICY: CREATE DATA_POLICY statement. * CREATE_PROPERTY_GRAPH: CREATE PROPERTY GRAPH statement. * CREATE_CAPACITY: CREATE CAPACITY statement. * CREATE_RESERVATION: CREATE RESERVATION statement. * CREATE_ASSIGNMENT: CREATE ASSIGNMENT statement. * DROP_TABLE: DROP TABLE statement. * DROP_EXTERNAL_TABLE: DROP EXTERNAL TABLE statement. * DROP_VIEW: DROP VIEW statement. * DROP_MODEL: DROP MODEL statement. * DROP_MATERIALIZED_VIEW: DROP MATERIALIZED VIEW statement. * DROP_FUNCTION: DROP FUNCTION statement. * DROP_TABLE_FUNCTION: DROP TABLE FUNCTION statement. * DROP_PROCEDURE: DROP PROCEDURE statement. * DROP_SEARCH_INDEX: DROP SEARCH INDEX statement. * DROP_VECTOR_INDEX: DROP VECTOR INDEX statement. * DROP_SCHEMA: DROP SCHEMA statement. * UNDROP_SCHEMA: UNDROP SCHEMA statement. * DROP_SNAPSHOT_TABLE: DROP SNAPSHOT TABLE statement. * DROP_ROW_ACCESS_POLICY: DROP [ALL] ROW ACCESS POLICY|POLICIES statement. * DROP_CONNECTION: DROP CONNECTION statement. * DROP_DATA_POLICY: DROP DATA_POLICY statement. * DROP_PROPERTY_GRAPH: DROP PROPERTY GRAPH statement. * DROP_CAPACITY: DROP CAPACITY statement. * DROP_RESERVATION: DROP RESERVATION statement. * DROP_ASSIGNMENT: DROP ASSIGNMENT statement. * ALTER_TABLE: ALTER TABLE statement. * ALTER_VIEW: ALTER VIEW statement. * ALTER_MATERIALIZED_VIEW: ALTER MATERIALIZED VIEW statement. * ALTER_SCHEMA: ALTER SCHEMA statement. * ALTER_MODEL: ALTER MODEL statement. * ALTER_SEARCH_INDEX: ALTER SEARCH INDEX statement. * ALTER_VECTOR_INDEX: ALTER VECTOR INDEX statement. * ALTER_CONNECTION: ALTER CONNECTION statement. * ALTER_DATA_POLICY: ALTER DATA_POLICY statement. * ALTER_PROJECT: ALTER PROJECT statement. * ALTER_ORGANIZATION: ALTER ORGANIZATION statement. * ALTER_BI_CAPACITY: ALTER BI_CAPACITY statement. * ALTER_CAPACITY: ALTER CAPACITY statement. * ALTER_RESERVATION: ALTER RESERVATION statement. * SCRIPT: SCRIPT statement. * CALL: CALL statement. * BEGIN_TRANSACTION: BEGIN TRANSACTION statement. * COMMIT_TRANSACTION: COMMIT TRANSACTION statement. * ROLLBACK_TRANSACTION: ROLLBACK TRANSACTION statement. * EXPORT_DATA: EXPORT DATA statement. * EXPORT_MODEL: EXPORT MODEL statement. * EXPORT_METADATA: EXPORT TABLE METADATA statement, for BigLake Iceberg tables. * LOAD_DATA: LOAD DATA statement. * GRANT_ON_SCHEMA: GRANT ... ON SCHEMA statement. * GRANT_ON_TABLE: GRANT ... ON TABLE statement. Also used for GRANT ... ON EXTERNAL TABLE. * GRANT_ON_VIEW: GRANT ... ON VIEW statement. * GRANT_ON_PROJECT: GRANT ... ON PROJECT statement. * REVOKE_ON_SCHEMA: REVOKE ... ON SCHEMA statement. * REVOKE_ON_TABLE: REVOKE ... ON TABLE statement. Also used for REVOKE ... ON EXTERNAL TABLE. * REVOKE_ON_VIEW: REVOKE ... ON VIEW statement. * REVOKE_ON_PROJECT: REVOKE ... ON PROJECT statement.

totalBytesBilledstring int64

Output only. If the project is configured to use on-demand pricing, then this field contains the total bytes billed for the job. If the project is configured to use flat-rate pricing, then you are not billed for bytes and this field is informational only.

totalBytesProcessedstring int64

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.

totalRowsstring uint64

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.

totalSlotMsstring int64

Output only. Number of slot ms the user is actually billed for.

Changes

    • info

      the security scope https://www.googleapis.com/auth/bigquery was added to the endpoint's security scheme Oauth2

    • info

      the security scope https://www.googleapis.com/auth/bigquery was added to the endpoint's security scheme Oauth2c

    • info

      the security scope https://www.googleapis.com/auth/cloud-platform.read-only was removed from the endpoint's security scheme Oauth2

    • info

      the security scope https://www.googleapis.com/auth/cloud-platform.read-only was removed from the endpoint's security scheme Oauth2c

    • info

      the security scope https://www.googleapis.com/auth/bigquery was added to the endpoint's security scheme Oauth2

    • info

      the security scope https://www.googleapis.com/auth/bigquery was added to the endpoint's security scheme Oauth2c

    • info

      the security scope https://www.googleapis.com/auth/cloud-platform.read-only was removed from the endpoint's security scheme Oauth2

    • info

      the security scope https://www.googleapis.com/auth/cloud-platform.read-only was removed from the endpoint's security scheme Oauth2c