System variables reference

BigQuery supports the following system variables formulti-statement queries or withinsessions.You can use system variables to set or retrieve information during queryexecution, similar to user-definedprocedural language variables.

NameTypeRead and write or read-onlyDescription
@@current_job_idSTRINGRead-only Job ID of the currently executing job. In the context of a multi-statement query, this returns the job responsible for the current statement, not the entire multi-statement query.
@@dataset_idSTRINGRead and write ID of the default dataset in the current project. This ID is used when a dataset is not specified for a project in the query. You can use theSET statement to assign@@dataset_id to another dataset ID in the current project. The system variables@@dataset_project_id and@@dataset_id can be set and used together.
@@dataset_project_idSTRINGRead and write ID of the default project that's used when one is not specified for a dataset used in the query. If@@dataset_project_id is not set, or if it is set toNULL, the query-executing project (@@project_id) is used. You can use theSET statement to assign@@dataset_project_id to another project ID. The system variables@@dataset_project_id and@@dataset_id can be set and used together.
@@last_job_idSTRINGRead-only Job ID of the most recent job to execute in the current multi-statement query, not including the current one. If the multi-statement query containsCALL statements, this job may have originated in a different procedure.
@@locationSTRINGRead and write The location in which to run the query.@@location can only be set to a string literal with avalid location. ASET @@location statement must be the first statement in a query. An error occurs if there is a mismatch between@@location and anotherlocation setting for the query. You can improve the latency of queries that set@@location by usingoptional job creation mode. You can use the@@location system variable inside ofSQL UDFs andtable functions.
@@project_idSTRINGRead-only ID of the project used to execute the current query. In the context of a procedure,@@project_id refers to the project that is running the multi-statement query, not the project which owns the procedure.
@@query_labelSTRINGRead and write Query label to associate with query jobs in the current multi-statement query or session. If set in a query, all subsequent query jobs in the script or session will have this label. If not set in a query, the value for this system variable isNULL. For an example of how to set this system variable, see Associate jobs in a session with a label.
@@reservationSTRINGRead and write [Preview]. Specifies the reservation where the job is run. Must be in the following format:projects/project_id/locations/location/reservations/reservation_id. The location of the reservation must match the location the query is running in.
@@row_countINT64Read-only If used in a multi-statement query and the previous statement is DML, specifies the number of rows inserted, modified, or deleted, as a result of that DML statement. If the previous statement is a `MERGE` statement,@@row_count represents the combined total number of rows inserted, modified, and deleted. This value isNULL if not in a multi-statement query.
@@script.bytes_billedINT64Read-only Total bytes billed so far in the currently executing multi-statement query job. This value isNULL if not in the job.
@@script.bytes_processedINT64Read-only Total bytes processed so far in the currently executing multi-statement query job. This value isNULL if not in the job.
@@script.creation_timeTIMESTAMPRead-only Creation time of the currently executing multi-statement query job. This value isNULL if not in the job.
@@script.job_idSTRINGRead-only Job ID of the currently executing multi-statement query job. This value isNULL if not in the job.
@@script.num_child_jobsINT64Read-only Number of currently completed child jobs. This value isNULL if not in the job.
@@script.slot_msINT64Read-only Number of slot milliseconds used so far by the script. This value isNULL if not in the job.
@@session_idINT64Read-only ID of the session that the current query is associated with.
@@time_zoneSTRINGRead and write The default time zone to use in time zone-dependent SQL functions, when a time zone is not specified as an argument.@@time_zone can be modified by using aSET statement to any valid time zone name. At the start of each script,@@time_zone begins as “UTC”.

For backward compatibility, expressions used in anOPTIONS orFOR SYSTEM TIME AS OF clause default to theAmerica/Los_Angeles time zone,while all other date/time expressions default to theUTC time zone. If@@time_zone has been set earlier in the multi-statement query, the chosentime zone will apply to all date/time expressions, includingOPTIONS andFOR SYSTEM TIME AS OF clauses.

In addition to the system variables shown previously, you can useEXCEPTION systemvariables during execution of a multi-statement query. For more informationabout theEXCEPTION system variables, see the procedural language statementBEGIN...EXCEPTION.

Examples

You don't create system variables, but you can overridethe default value for some of them:

SET@@dataset_project_id='MyProject';

The following query returns the default time zone:

SELECT@@time_zoneASdefault_time_zone;
+-------------------+| default_time_zone |+-------------------+| UTC               |+-------------------+

You can use system variables with DDL and DML queries.For example, here are a few ways to use the system variable@@time_zonewhen creating and updating a table:

BEGINCREATETEMPTABLEMyTempTableASSELECT@@time_zoneASdefault_time_zone;END;
CREATEORREPLACETABLEMyDataset.MyTable(default_time_zoneSTRING)OPTIONS(description=@@time_zone);
UPDATEMyDataset.MyTableSETdefault_time_zone=@@time_zoneWHERETRUE;

There are some places where system variables can't be used inDDL and DML queries. For example, you can't use a system variable as aproject name, dataset, or table name. The following query produces an error whenyou include the@@dataset_id system variable in a table path:

BEGINCREATETEMPTABLE@@dataset_id.MyTempTable(idSTRING);END;

For more examples of how you can use system variables in multi-statement queries,seeSet a variable.

For examples of how you can use system variables in sessions, seeExample session.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.