Stay organized with collections
Save and categorize content based on your preferences.
Table decorators in legacy SQL
Normally, BigQuery performs a full column scan when
running a query.
You can use table decorators in legacy SQL to perform a more cost-effective query of a
subset of your data. Table decorators can be used whenever a table is read,
such as when copying a table,
exporting a table,
or listing data using tabledata.list.
Table decorators support relative and absolute values. Relative
values are indicated by a negative number, and absolute
values are indicated by a positive number. For example, -3600000 indicates one
hour ago in milliseconds, relative to the current time; 3600000
indicates one hour in milliseconds after 1/1/1970.
Time decorators
Time decorators (formerly known as snapshot decorators) reference a table's
historical data at a point in time.
Syntax
@
References a table's historical data at ,
in milliseconds since the epoch.
must be within the last seven days and
greater than or equal to the table's creation time, but less than the table's
deletion or expiration time.
@0 is a special case that references the oldest data available for the
table.
Time decorators are also used outside of legacy SQL. You can use them in the
bq cp command to
restore deleted tables
within seven days of table deletion.
Examples
To get the historical data for a table at one hour ago:
Relative value example
#legacySQL
SELECT COUNT(*) FROM [PROJECT_ID:DATASET.TABLE@-3600000]
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-05 UTC."],[[["Table decorators in legacy SQL allow for cost-effective querying of data subsets, as opposed to full column scans, and can be used when copying, exporting, or listing table data."],["Time decorators, indicated by `@\u003ctime\u003e`, reference a table's historical data at a specific point in time, measured in milliseconds since the epoch and within the last seven days."],["Range decorators, using the `@\u003ctime1\u003e-\u003ctime2\u003e` syntax, specify a range of time to target data added between the two times, with the second time defaulting to \"now\" if not specified."],["Time decorators can also be used in the `bq cp` command to restore tables deleted within seven days, expanding beyond their usage just within SQL queries."],["GoogleSQL's `FOR SYSTEM_TIME AS OF` clause and time-partitioned tables offer comparable functionality to time and range decorators, respectively, making table decorators not available in GoogleSQL."]]],[]]