BigQuery System Variables: How to Use Them in Multi-Statement Queries

June 24, 2024 at 8:46:54 AM

BigQuery System Variables: How to Use Them in Multi-Statement Queries

System variables in BigQuery are special types of variables available in scripts (multi-statement queries) that allow users to read and sometimes write query metadata during execution. These variables can be used to set or retrieve information, similar to user-defined procedural language variables.

Examples of System Variables

  • @@query_label: Read/write query labels to group queries.
  • @@time_zone: Read/write default time zone.
  • @@script.job_id: Job ID of the current job.

Below is a list of all supported system variables in BigQuery, sourced from the documentation.

Name Type Access Description
@@current_job_id STRING Read-only Job ID of the currently executing job.
@@dataset_id STRING Read and write ID of the default dataset in the current project.
@@dataset_project_id STRING Read and write ID of the default project used when one is not specified for a dataset.
@@last_job_id STRING Read-only Job ID of the most recent job to execute in the current multi-statement query.
@@project_id STRING Read-only ID of the project used to execute the current query.
@@query_label STRING Read and write Query label to associate with query jobs in the current multi-statement query or session.
@@row_count INT64 Read-only Number of rows modified, inserted, or deleted by the previous DML statement.
@@script.bytes_billed INT64 Read-only Total bytes billed so far in the currently executing multi-statement query job.
@@script.bytes_processed INT64 Read-only Total bytes processed so far in the currently executing multi-statement query job.
@@script.creation_time TIMESTAMP Read-only Creation time of the currently executing multi-statement query job.
@@script.job_id STRING Read-only Job ID of the currently executing multi-statement query job.
@@script.num_child_jobs INT64 Read-only Number of currently completed child jobs.
@@script.slot_ms INT64 Read-only Number of slot milliseconds used so far by the script.
@@session_id INT64 Read-only ID of the session that the current query is associated with.
@@time_zone STRING Read and write Default time zone to use in time zone-dependent SQL functions.

Additional Information

  • EXCEPTION System Variables: These can be used during the execution of a multi-statement query. For more details, refer to the procedural language statement BEGIN...EXCEPTION.

These system variables enhance the ability to manage and retrieve metadata during query execution, making it easier to handle complex queries and scripts in BigQuery.

Have more questions on this topic? Ask our AI assistant for in-depth insights.

Read more from sources 👇

Constantin Lungu
Constantin Lungu

Top Creator

Top BigQuery Creator

Constantin Lungu is a Top BigQuery Creator. Part of Swipe Insight Select, a curated list of top creators.

Top BigQuery Creator
- System variables in BigQuery are special variables available in multi-statement queries, allowing users to read and some... Visit Source Open external source URL

Want Personalized Digital Marketing Insights at Your Preferred Time?

Our Smart Newsletter brings you the latest insights on the topics you love, delivered at your preferred time and frequency.

Discover More

BigQuery Now Allows Drag-and-Drop Tabs

BigQuery Now Allows Drag-and-Drop Tabs

54 years ago

Google Cloud
Google Cloud

Official Source

Official Source

Google Cloud is a Official Source. The source has been verified by Swipe Insight team.

Official Source
BigQuery tables now support tags for conditional access control using IAM policies

BigQuery tables now support tags for conditional access control using IAM policies

54 years ago

Google Cloud
Google Cloud

Official Source

Official Source

Google Cloud is a Official Source. The source has been verified by Swipe Insight team.

Official Source
BigQuery Adds JupyterLab Plugin for Data Exploration and Deployment

BigQuery Adds JupyterLab Plugin for Data Exploration and Deployment

54 years ago

Google Cloud
Google Cloud

Official Source

Official Source

Google Cloud is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Facebook Ads Transfer in BigQuery Now Supports Adjustable Refresh Window

Facebook Ads Transfer in BigQuery Now Supports Adjustable Refresh Window

54 years ago

BigQuery Job History: Retrieve, Analyze, and Manage Queries Effortlessly

BigQuery Job History: Retrieve, Analyze, and Manage Queries Effortlessly

54 years ago

Constantin Lungu
Constantin Lungu

Top Creator

Top BigQuery Creator

Constantin Lungu is a Top BigQuery Creator. Part of Swipe Insight Select, a curated list of top creators.

Top BigQuery Creator
Understanding SQL Anti-Joins: Retain Rows Not Found in Another Table

Understanding SQL Anti-Joins: Retain Rows Not Found in Another Table

54 years ago

Constantin Lungu
Constantin Lungu

Top Creator

Top BigQuery Creator

Constantin Lungu is a Top BigQuery Creator. Part of Swipe Insight Select, a curated list of top creators.

Top BigQuery Creator