{"title":"Connect a DuckDB database","description":"Connect an existing DuckDB database file from object storage as an external catalog for federated queries in Altertable.","order":140,"askSuggestions":["Can I write to a connected DuckDB database?","When should I use an Altertable catalog instead?"],"navigation":true,"body":{"code":"var Component=(()=>{var b=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),x=(t,e)=>{for(var a in e)r(t,a,{get:e[a],enumerable:!0})},i=(t,e,a,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of k(e))!p.call(t,o)&&o!==a&&r(t,o,{get:()=>e[o],enumerable:!(c=g(e,o))||c.enumerable});return t};var f=(t,e,a)=>(a=t!=null?b(D(t)):{},i(e||!t||!t.__esModule?r(a,\"default\",{value:t,enumerable:!0}):a,t)),w=t=>i(r({},\"__esModule\",{value:!0}),t);var d=m((C,l)=>{l.exports=_jsx_runtime});var y={};x(y,{default:()=>u,frontmatter:()=>B});var n=f(d()),B={title:\"Connect a DuckDB database\",description:\"Connect an existing DuckDB database file from object storage as an external catalog for federated queries in Altertable.\",order:140,askSuggestions:[\"Can I write to a connected DuckDB database?\",\"When should I use an Altertable catalog instead?\"]};function s(t){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",ol:\"ol\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...t.components},{DocsPreviewDocument:a,DocsPreviewSection:c}=e;return a||h(\"DocsPreviewDocument\",!0),c||h(\"DocsPreviewSection\",!0),(0,n.jsxs)(a,{anchors:\"connect-a-duckdb-database requirements connect-a-duckdb-catalog query-example when-to-use-an-altertable-catalog-instead\",children:[(0,n.jsxs)(c,{sectionId:\"connect-a-duckdb-database\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"connect-a-duckdb-database\",children:\"Connect a DuckDB database\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"DuckDB external catalogs expose an existing \",(0,n.jsx)(e.code,{children:\".duckdb\"}),\" database file that already lives in a connected bucket. Use this when another process produces a DuckDB database and you want to query it from Altertable without importing it into an Altertable catalog.\"]}),`\n`]}),(0,n.jsxs)(c,{sectionId:\"requirements\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"requirements\",children:\"Requirements\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"A \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/storage/buckets\",children:\"bucket\"}),\" connected to the environment\"]}),`\n`,(0,n.jsx)(e.li,{children:\"A DuckDB database file stored in that bucket\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"A path ending in \",(0,n.jsx)(e.code,{children:\".duckdb\"})]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"DuckDB catalogs are read-only in Altertable.\"}),`\n`]}),(0,n.jsxs)(c,{sectionId:\"connect-a-duckdb-catalog\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,n.jsx)(e.h2,{id:\"connect-a-duckdb-catalog\",children:\"Connect a DuckDB Catalog\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Open \",(0,n.jsx)(e.strong,{children:\"Catalogs\"}),\" in the target environment.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Click \",(0,n.jsx)(e.strong,{children:\"New catalog\"}),\" and choose \",(0,n.jsx)(e.strong,{children:\"DuckDB\"}),\".\"]}),`\n`,(0,n.jsx)(e.li,{children:\"Select the bucket that contains the DuckDB file.\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"Enter the path to the \",(0,n.jsx)(e.code,{children:\".duckdb\"}),\" file, such as \",(0,n.jsx)(e.code,{children:\"exports/reporting.duckdb\"}),\".\"]}),`\n`,(0,n.jsx)(e.li,{children:\"Test and create the catalog.\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"After the catalog is created, its schemas and tables appear in the catalog browser and can be queried with SQL.\"}),`\n`]}),(0,n.jsxs)(c,{sectionId:\"query-example\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,n.jsx)(e.h2,{id:\"query-example\",children:\"Query Example\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT\n  customer_id,\n  total_revenue\nFROM reporting_duckdb.main.customer_revenue\nORDER BY total_revenue DESC\nLIMIT 25;\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"You can join DuckDB catalog tables with Altertable catalogs and other external catalogs in the same query.\"}),`\n`]}),(0,n.jsxs)(c,{sectionId:\"when-to-use-an-altertable-catalog-instead\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,n.jsx)(e.h2,{id:\"when-to-use-an-altertable-catalog-instead\",children:\"When to Use an Altertable Catalog Instead\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Use an \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/catalogs\",children:\"Altertable catalog\"}),\" when Altertable should own the storage layout, snapshots, writes, and retention. Use a DuckDB external catalog when the \",(0,n.jsx)(e.code,{children:\".duckdb\"}),\" file is produced elsewhere and Altertable only needs read access.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"For other DuckDB workflows, see the \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/integrations/duckdb\",children:\"DuckDB integration hub\"}),\".\"]})]})]})}function u(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(s,{...t})}):s(t)}function h(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return w(y);})();\n;return Component;"},"_id":"docs/lakehouse/external-catalogs/duckdb.mdx","_raw":{"sourceFilePath":"docs/lakehouse/external-catalogs/duckdb.mdx","sourceFileName":"duckdb.mdx","sourceFileDir":"docs/lakehouse/external-catalogs","contentType":"mdx","flattenedPath":"docs/lakehouse/external-catalogs/duckdb"},"type":"Docs","path":"/lakehouse/external-catalogs/duckdb","level":3,"parent":"lakehouse/external-catalogs"}