{"title":"Time travel","description":"Query Altertable catalog tables as of earlier snapshots using version or timestamp bounds for audits and reproducible reports.","order":630,"askSuggestions":["How do I query a table as it was last week?","How long does Altertable keep snapshots?","How do I add a commit message to a snapshot?"],"navigation":true,"routeId":"lakehouseTimeTravel","body":{"code":"var Component=(()=>{var m=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var b=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var s in e)o(t,s,{get:e[s],enumerable:!0})},c=(t,e,s,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of g(e))!y.call(t,r)&&r!==s&&o(t,r,{get:()=>e[r],enumerable:!(a=u(e,r))||a.enumerable});return t};var _=(t,e,s)=>(s=t!=null?m(f(t)):{},c(e||!t||!t.__esModule?o(s,\"default\",{value:t,enumerable:!0}):s,t)),v=t=>c(o({},\"__esModule\",{value:!0}),t);var l=b((x,h)=>{h.exports=_jsx_runtime});var k={};w(k,{default:()=>p,frontmatter:()=>L});var n=_(l()),L={title:\"Time travel\",routeId:\"lakehouseTimeTravel\",description:\"Query Altertable catalog tables as of earlier snapshots using version or timestamp bounds for audits and reproducible reports.\",order:630,askSuggestions:[\"How do I query a table as it was last week?\",\"How long does Altertable keep snapshots?\",\"How do I add a commit message to a snapshot?\"]};function d(t){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",p:\"p\",pre:\"pre\",strong:\"strong\",table:\"table\",tbody:\"tbody\",td:\"td\",th:\"th\",thead:\"thead\",tr:\"tr\",ul:\"ul\",...t.components},{DocsPreviewDocument:s,DocsPreviewSection:a,DocsTable:r}=e;return s||i(\"DocsPreviewDocument\",!0),a||i(\"DocsPreviewSection\",!0),r||i(\"DocsTable\",!0),(0,n.jsxs)(s,{anchors:\"time-travel query-at-a-snapshot snapshots list-snapshots current-snapshot-helpers commit-messages snapshot-retention learn-more\",children:[(0,n.jsxs)(a,{sectionId:\"time-travel\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"time-travel\",children:\"Time Travel\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Every catalog snapshot represents a consistent state of the database. Altertable keeps a record of historic snapshots and their changesets until compaction removes snapshots that fall outside \",(0,n.jsx)(e.a,{href:\"#snapshot-retention\",children:\"retention\"}),\".\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Time travel lets you query table state as of any recorded snapshot. Specify the snapshot with a version ID or a timestamp. Use the \",(0,n.jsx)(e.code,{children:\"snapshots\"}),\" function to list valid snapshots for a catalog.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Run the statements below through Altertable's \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/sql-engine\",children:\"SQL engine\"}),\" against an \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/catalogs\",children:\"Altertable catalog\"}),\" you own.\"]}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"query-at-a-snapshot\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"query-at-a-snapshot\",children:\"Query at a snapshot\"}),`\n`,(0,n.jsx)(e.p,{children:\"Query a table at a specific snapshot version:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT sku, label\nFROM my_catalog.main.product_skus AT (VERSION => 3);\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"Query a table as it was at a point in time:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT sku, label\nFROM my_catalog.main.product_skus AT (TIMESTAMP => now() - INTERVAL '1 week');\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"Time travel applies to individual table references in a query. Join current and historical data by mixing plain and \",(0,n.jsx)(e.code,{children:\"AT\"}),\" table references in the same statement. To inspect row-level inserts, updates, and deletes instead of full table state, use the \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/features/data-change-feed\",children:\"data change feed\"}),\".\"]}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"snapshots\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,n.jsx)(e.h2,{id:\"snapshots\",children:\"Snapshots\"}),`\n`,(0,n.jsx)(e.p,{children:\"Snapshots are commits to a catalog. Each snapshot applies a set of changes \\u2014 creating tables, inserting or deleting rows, altering schemas \\u2014 that move the catalog to a new consistent state. Every write goes through a snapshot; changes cannot land outside a transaction.\"}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"list-snapshots\",anchors:\"\",ancestors:\"snapshots\",index:\"3\",children:[(0,n.jsx)(e.h3,{id:\"list-snapshots\",children:\"List snapshots\"}),`\n`,(0,n.jsx)(e.p,{children:\"Query all snapshots and their changesets:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT *\nFROM my_catalog.snapshots();\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"After creating a table and inserting a row, the history might look like this:\"}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"snapshot_id\"}),(0,n.jsx)(e.th,{children:\"snapshot_time\"}),(0,n.jsx)(e.th,{children:\"schema_version\"}),(0,n.jsx)(e.th,{children:\"changes\"}),(0,n.jsx)(e.th,{children:\"author\"}),(0,n.jsx)(e.th,{children:\"commit_message\"}),(0,n.jsx)(e.th,{children:\"commit_extra_info\"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:\"0\"}),(0,n.jsx)(e.td,{children:\"2026-04-10 12:57:02+02\"}),(0,n.jsx)(e.td,{children:\"0\"}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"{schemas_created=[main]}\"})}),(0,n.jsx)(e.td,{children:\"NULL\"}),(0,n.jsx)(e.td,{children:\"NULL\"}),(0,n.jsx)(e.td,{children:\"NULL\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:\"1\"}),(0,n.jsx)(e.td,{children:\"2026-04-10 12:57:02+02\"}),(0,n.jsx)(e.td,{children:\"1\"}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"{tables_created=[main.product_skus]}\"})}),(0,n.jsx)(e.td,{children:\"NULL\"}),(0,n.jsx)(e.td,{children:\"NULL\"}),(0,n.jsx)(e.td,{children:\"NULL\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:\"2\"}),(0,n.jsx)(e.td,{children:\"2026-04-10 12:57:02+02\"}),(0,n.jsx)(e.td,{children:\"1\"}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"{inlined_insert=[1]}\"})}),(0,n.jsx)(e.td,{children:\"NULL\"}),(0,n.jsx)(e.td,{children:\"NULL\"}),(0,n.jsx)(e.td,{children:\"NULL\"})]})]})]}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"current-snapshot-helpers\",anchors:\"\",ancestors:\"snapshots\",index:\"4\",children:[(0,n.jsx)(e.h3,{id:\"current-snapshot-helpers\",children:\"Current snapshot helpers\"}),`\n`,(0,n.jsx)(e.p,{children:\"Read the latest snapshot ID:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`FROM my_catalog.current_snapshot();\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"When multiple connections write to the same catalog, read the latest snapshot committed on the current connection:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`FROM my_catalog.last_committed_snapshot();\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"A new connection returns \",(0,n.jsx)(e.code,{children:\"NULL\"}),\" from \",(0,n.jsx)(e.code,{children:\"last_committed_snapshot()\"}),\" until it commits its own transaction.\"]}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"commit-messages\",anchors:\"\",ancestors:\"snapshots\",index:\"5\",children:[(0,n.jsx)(e.h3,{id:\"commit-messages\",children:\"Commit messages\"}),`\n`,(0,n.jsx)(e.p,{children:\"Attach author, message, and optional metadata to a snapshot inside a transaction:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`BEGIN;\n\nINSERT INTO my_catalog.main.product_skus VALUES ('SKU-003', 'Walnut desk');\n\nCALL my_catalog.set_commit_message(\n  'alex',\n  'Add walnut desk SKU',\n  extra_info => '{\"ticket\": \"CAT-42\"}'\n);\n\nCOMMIT;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"Those fields appear on the corresponding row in \",(0,n.jsx)(e.code,{children:\"snapshots()\"}),\":\"]}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"snapshot_id\"}),(0,n.jsx)(e.th,{children:\"author\"}),(0,n.jsx)(e.th,{children:\"commit_message\"}),(0,n.jsx)(e.th,{children:\"commit_extra_info\"})]})}),(0,n.jsx)(e.tbody,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:\"3\"}),(0,n.jsx)(e.td,{children:\"alex\"}),(0,n.jsx)(e.td,{children:\"Add walnut desk SKU\"}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:'{\"ticket\": \"CAT-42\"}'})})]})})]}),`\n`,(0,n.jsx)(e.p,{children:\"Use commit messages when auditing who changed a catalog and why.\"}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"snapshot-retention\",anchors:\"\",ancestors:\"\",index:\"6\",children:[(0,n.jsx)(e.h2,{id:\"snapshot-retention\",children:\"Snapshot retention\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.strong,{children:\"Snapshot retention\"}),\" setting on an Altertable catalog controls how long old snapshots are kept. Retention applies in the catalog UI when you create or edit a catalog.\"]}),`\n`,(0,n.jsx)(r,{columns:[\"Value\",\"Behavior\"],data:[{Value:\"Blank\",Behavior:\"Retain snapshots indefinitely\"},{Value:\"`0`\",Behavior:\"Disable snapshot retention after cleanup runs\"},{Value:\"`N` days\",Behavior:\"Retain snapshots newer than `N` days\"}]}),`\n`,(0,n.jsx)(e.p,{children:\"Set a retention period when storage cost or compliance requires old table versions to expire. Leave it blank when long-running time travel and historical auditability matter more than storage cleanup.\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Expired snapshots limit how far back you can query with \",(0,n.jsx)(e.code,{children:\"AT\"}),\" and how much history the \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/features/data-change-feed\",children:\"data change feed\"}),\" can return.\"]}),`\n`]}),(0,n.jsxs)(a,{sectionId:\"learn-more\",anchors:\"\",ancestors:\"\",index:\"7\",children:[(0,n.jsx)(e.h2,{id:\"learn-more\",children:\"Learn more\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:(0,n.jsx)(e.a,{href:\"/docs/lakehouse/features/transactions\",children:\"Transactions\"})}),\": Each committed transaction creates one snapshot\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:(0,n.jsx)(e.a,{href:\"/docs/lakehouse/features/data-change-feed\",children:\"Data Change Feed\"})}),\": Read row-level changes between snapshots\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:(0,n.jsx)(e.a,{href:\"/docs/lakehouse\",children:\"Altertable Catalogs\"})}),\": Catalogs for storing and querying your data\"]}),`\n`]})]})]})}function p(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(d,{...t})}):d(t)}function i(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return v(k);})();\n;return Component;"},"_id":"docs/lakehouse/features/time-travel.mdx","_raw":{"sourceFilePath":"docs/lakehouse/features/time-travel.mdx","sourceFileName":"time-travel.mdx","sourceFileDir":"docs/lakehouse/features","contentType":"mdx","flattenedPath":"docs/lakehouse/features/time-travel"},"type":"Docs","path":"/lakehouse/features/time-travel","level":3,"parent":"lakehouse/features"}