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

June 24, 2024 at 8:46:54 AM

TL;DR System variables in BigQuery are special variables available in multi-statement queries, allowing users to read and sometimes write query metadata during execution. Examples include @@query_label for query labels, @@time_zone for default time zones, and @@script.job_id for the current job ID. They help set or retrieve information similar to user-defined variables like @@current_job_id and @@dataset_id, providing specific data about the query context.

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

The Only Digital Marketing Feed You'll Ever Need.

Stay informed your way. Tailored updates when and how you want them. 100% Free.

10,000+ Users

500+ Sources

1000+ Tools

Or

Related Posts

Google Cloud Code Extension Adds BigQuery Support in VS Code

Google Cloud Code Extension Adds BigQuery Support in VS Code

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
Tired of spending too much time creating audits for your clients?

Tired of spending too much time creating audits for your clients?

Featured
BigQuery Introduces Commercial Data Sharing via Cloud Marketplace

BigQuery Introduces Commercial Data Sharing via Cloud Marketplace

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
Google Sheets Integrates BigQuery Saved Queries

Google Sheets Integrates BigQuery Saved Queries

Google
Google

Official Source

Official Source

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

Official Source
BigQuery Expands Search Index Capabilities with INT64 and TIMESTAMP Support

BigQuery Expands Search Index Capabilities with INT64 and TIMESTAMP Support

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
Google Ends Free Access to Gemini in BigQuery, Announces Paid Plans

Google Ends Free Access to Gemini in BigQuery, Announces Paid Plans

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
Google Cloud Enhances Looker with Major User Experience Updates

Google Cloud Enhances Looker with Major User Experience Updates

Sean Zinsmeister
Sean Zinsmeister

Official Source

Official Source

Sean Zinsmeister is a Official Source. The source has been verified by Swipe Insight team.

Official Source
BigQuery Launches Gemini-Enhanced SQL Translation Features

BigQuery Launches Gemini-Enhanced SQL Translation Features

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

Related Tools

Marketing Auditor logo

Marketing Auditor

Verified Tool

Verified Tool

Marketing Auditor is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Automated audits for Google Ads and Analytics.

Get Featured Here

Showcase your tool in this list.

Contact Us
Databricks logo

Databricks

Generative AI-powered data intelligence platform

Data Engineering
GA4 SQL logo

GA4 SQL

Verified Tool

Verified Tool

GA4 SQL is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Generate GA4 BigQuery queries easily

Data Analysis
TapClicks logo

TapClicks

Automated marketing solutions powered by your data

Data Engineering
Stitch logo

Stitch

Automated cloud data pipelines, no coding needed

Data Engineering
Akkio logo

Akkio

AI-powered analytics for agencies

Data Analysis
NinjaCat logo

NinjaCat

AI-powered marketing data and analytics platform

Reporting
Funnel logo

Funnel

Aggregate and analyze marketing data seamlessly

Reporting
Fivetran logo

Fivetran

Effortlessly centralize and move data from any source

Data Engineering
Power My Analytics logo

Power My Analytics

Automate and integrate your marketing data

Reporting

Get Featured Here

Showcase your tool in this list.

Contact Us