[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-25。"],[[["\u003cp\u003eBigQuery allows querying and restoring data that has been changed or deleted within a specified time travel window.\u003c/p\u003e\n"],["\u003cp\u003eYou can query historical table data at any point within the time travel window using the \u003ccode\u003eFOR SYSTEM_TIME AS OF\u003c/code\u003e clause in GoogleSQL.\u003c/p\u003e\n"],["\u003cp\u003eTables can be restored from historical data by copying it into a new table, even if the original table was deleted or has expired.\u003c/p\u003e\n"],["\u003cp\u003eTo restore a table, use the \u003ccode\u003etableid@TIME\u003c/code\u003e, \u003ccode\u003etableid@-TIME_OFFSET\u003c/code\u003e, or \u003ccode\u003etableid@0\u003c/code\u003e syntax to specify the desired historical version.\u003c/p\u003e\n"],["\u003cp\u003eIf the specified timestamp is outside the time travel window or before the table was created, the query will fail and return an error.\u003c/p\u003e\n"]]],[],null,["# Access historical data\n======================\n\nBigQuery lets you query and restore data stored in\nBigQuery that has been changed or deleted within your\n[time travel](/bigquery/docs/time-travel) window.\n\nQuery data at a point in time\n-----------------------------\n\nYou can query a table's historical data from any point in time within the\ntime travel window by using a\n[`FOR SYSTEM_TIME AS OF`](/bigquery/docs/reference/standard-sql/query-syntax#for_system_time_as_of)\nclause. This clause takes a constant timestamp expression and references the\nversion of the table that was current at that timestamp. The table must be\nstored in BigQuery; it cannot be an external table. There is no\nlimit on table size when using `SYSTEM_TIME AS OF`.\n\nFor example, the following query returns a historical version of the table\nfrom one hour ago: \n\n SELECT *\n FROM `mydataset.mytable`\n FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR);\n\n| **Note:** The `FOR SYSTEM_TIME AS OF` clause is supported in GoogleSQL. For legacy SQL, [time decorators](/bigquery/docs/table-decorators#time_decorators) provide equivalent functionality.\n\nIf the timestamp specifies a time from prior to the time travel window or from\nbefore the table was created, then the query fails and returns an error like the\nfollowing: \n\n```\nInvalid snapshot time 1601168925462 for table\nmyproject:mydataset.table1@1601168925462. Cannot read before 1601573410026.\n```\n\nAfter you replace an existing table by using the `CREATE OR REPLACE TABLE`\nstatement, you can use `FOR SYSTEM_TIME AS OF` to query the previous version of\nthe table.\n\nIf the table was deleted, then the query fails and returns an error like the\nfollowing: \n\n```\nNot found: Table myproject:mydataset.table was not found in location LOCATION\n```\n\nRestore a table from a point in time\n------------------------------------\n\nYou can restore a table from historical data by copying the historical data into\na table. Copying historical data works even if the table was deleted or has\nexpired, as long as you restore the table within the duration of the time travel\nwindow.\n| **Note:** To restore data from a deleted table, you need to have the `bigquery.admin` role on the corresponding table.\n\nTo copy historical data from a table, add a decorator to the table name using\none of the following syntaxes:\n\n- `tableid@`\u003cvar translate=\"no\"\u003eTIME\u003c/var\u003e where \u003cvar translate=\"no\"\u003eTIME\u003c/var\u003e is the number of milliseconds since the Unix epoch.\n- `tableid@-`\u003cvar translate=\"no\"\u003eTIME_OFFSET\u003c/var\u003e where \u003cvar translate=\"no\"\u003eTIME_OFFSET\u003c/var\u003e is the relative offset from the current time, in milliseconds.\n- `tableid@0`: Specifies the oldest available historical data.\n\nFor example, the following bq command-line tool command copies a table named `table1` from\none hour ago into a table named `table1_restored`. The time, `-3600000`, is\nspecified in milliseconds using a relative offset. \n\n```bash\nbq cp mydataset.table1@-3600000 mydataset.table1_restored\n```\n\nRun the following command to get the equivalent Unix epoch time for a time\nthat you specify:\n\n\u003cbr /\u003e\n\n```googlesql\n date -d '2023-08-04 16:00:34.456789Z' +%s000\n \n```\n\n\u003cbr /\u003e\n\nThe following bq command-line tool command copies a table named `table1` into a table\nnamed `table1_restored`. Replace the UNIX epoch time `1691164834000` that you\nreceived from the previous command. \n\n bq cp mydataset.table1@1691164834000 mydataset.table1_restored\n\nFor more information, see\n[Restore deleted tables](/bigquery/docs/restore-deleted-tables).\n\nWhat's next\n-----------\n\n- Learn more about [table snapshots](/bigquery/docs/table-snapshots-intro).\n- Learn more about [Data retention with time travel and fail-safe](/bigquery/docs/time-travel).\n- Learn more about [managing tables](/bigquery/docs/managing-tables)."]]