{"title":"Query Altertable from DuckDB","description":"Query Altertable databases from DuckDB with the community extension and work with lakehouse data from local SQL workflows.","order":200,"askSuggestions":["How do I store my credentials as a DuckDB secret?","How do I export an Altertable table to Parquet locally?"],"navigation":true,"body":{"code":"var Component=(()=>{var b=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),A=(a,e)=>{for(var n in e)l(a,n,{get:e[n],enumerable:!0})},i=(a,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of D(e))!g.call(a,r)&&r!==n&&l(a,r,{get:()=>e[r],enumerable:!(o=p(e,r))||o.enumerable});return a};var k=(a,e,n)=>(n=a!=null?b(E(a)):{},i(e||!a||!a.__esModule?l(n,\"default\",{value:a,enumerable:!0}):n,a)),x=a=>i(l({},\"__esModule\",{value:!0}),a);var h=f((w,d)=>{d.exports=_jsx_runtime});var S={};A(S,{default:()=>m,frontmatter:()=>y});var t=k(h()),y={title:\"Query Altertable from DuckDB\",description:\"Query Altertable databases from DuckDB with the community extension and work with lakehouse data from local SQL workflows.\",order:200,askSuggestions:[\"How do I store my credentials as a DuckDB secret?\",\"How do I export an Altertable table to Parquet locally?\"]};function u(a){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...a.components},{CodeSnippet:n,DocsPreviewDocument:o,DocsPreviewSection:r,DocsTable:c}=e;return n||s(\"CodeSnippet\",!0),o||s(\"DocsPreviewDocument\",!0),r||s(\"DocsPreviewSection\",!0),c||s(\"DocsTable\",!0),(0,t.jsxs)(o,{anchors:\"query-altertable-from-duckdb installation attach-a-database connection-parameters query-a-remote-table filter-results export-to-local-files\",children:[(0,t.jsxs)(r,{sectionId:\"query-altertable-from-duckdb\",sectionTitle:\"Query Altertable from DuckDB\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,t.jsx)(e.h1,{id:\"query-altertable-from-duckdb\",children:\"Query Altertable from DuckDB\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"The \",(0,t.jsx)(e.a,{href:\"https://github.com/altertable-ai/duckdb-altertable\",children:\"DuckDB Altertable extension\"}),\" connects DuckDB to Altertable. Use it when you want to query governed Altertable data from DuckDB or join it with local files.\"]}),`\n`,(0,t.jsx)(e.p,{children:\"The extension supports:\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"Attached databases\"}),\" for querying Altertable catalogs with standard SQL\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"Direct table access\"}),\" through DuckDB's catalog\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"Raw query execution\"}),\" for remote SQL statements\"]}),`\n`]}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"installation\",sectionTitle:\"Installation\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,t.jsx)(e.h2,{id:\"installation\",children:\"Installation\"}),`\n`,(0,t.jsx)(e.p,{children:\"Install and load the community extension from DuckDB:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`INSTALL altertable FROM community;\nLOAD altertable;\n`})}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"attach-a-database\",sectionTitle:\"Attach a database\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,t.jsx)(e.h2,{id:\"attach-a-database\",children:\"Attach a database\"}),`\n`,(0,t.jsx)(e.p,{children:\"Use your lakehouse username, lakehouse password, and catalog in the connection string:\"}),`\n`,(0,t.jsx)(n,{language:\"sql\",children:`ATTACH\n  'user={{LAKEHOUSE_USERNAME}} password={{LAKEHOUSE_PASSWORD}} catalog=my_catalog'\n  AS remote_db (TYPE ALTERTABLE);`}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"connection-parameters\",sectionTitle:\"Connection parameters\",anchors:\"\",ancestors:\"attach-a-database\",index:\"3\",children:[(0,t.jsx)(e.h3,{id:\"connection-parameters\",children:\"Connection parameters\"}),`\n`,(0,t.jsx)(c,{columns:[\"Parameter\",\"Description\",\"Example\"],data:[{Parameter:\"`user`\",Description:\"Lakehouse username\",Example:\"`{{LAKEHOUSE_USERNAME}}`\"},{Parameter:\"`password`\",Description:\"Lakehouse password\",Example:\"`{{LAKEHOUSE_PASSWORD}}`\"},{Parameter:\"`catalog`\",Description:\"Remote Altertable catalog\",Example:\"`analytics`\"}]}),`\n`,(0,t.jsx)(e.p,{children:\"Or use DuckDB secrets:\"}),`\n`,(0,t.jsx)(n,{language:\"sql\",children:`CREATE SECRET my_altertable (\n    TYPE altertable,\n    USER '{{LAKEHOUSE_USERNAME}}',\n    PASSWORD '{{LAKEHOUSE_PASSWORD}}',\n    CATALOG 'my_catalog'\n);\n\nATTACH '' AS remote_db (TYPE altertable, SECRET my_altertable);`}),`\n`,(0,t.jsx)(e.p,{children:\"To disconnect the attached catalog:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`DETACH remote_db;\n`})}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"query-a-remote-table\",sectionTitle:\"Query a remote table\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,t.jsx)(e.h2,{id:\"query-a-remote-table\",children:\"Query a remote table\"}),`\n`,(0,t.jsx)(e.p,{children:\"Query tables through the attached Altertable database:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`SELECT * FROM remote_db.main.orders;\n`})}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"filter-results\",sectionTitle:\"Filter results\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,t.jsx)(e.h2,{id:\"filter-results\",children:\"Filter results\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Run \",(0,t.jsx)(e.code,{children:\"SELECT\"}),\" queries against attached Altertable tables:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`SELECT order_id, amount, status\nFROM remote_db.main.orders\nWHERE status = 'open';\n`})}),`\n`]}),(0,t.jsxs)(r,{sectionId:\"export-to-local-files\",sectionTitle:\"Export to local files\",anchors:\"\",ancestors:\"\",index:\"6\",children:[(0,t.jsx)(e.h2,{id:\"export-to-local-files\",children:\"Export to local files\"}),`\n`,(0,t.jsx)(e.p,{children:\"Export attached tables to local files:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`COPY remote_db.main.orders TO 'orders.csv';\nCOPY remote_db.main.orders TO 'orders.parquet';\nCOPY remote_db.main.orders TO 'orders.json';\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"For Python DataFrame workflows, see \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/query/pandas-polars-ibis\",children:\"Query with Pandas, Polars, and Ibis\"}),\". For ingesting data from DuckDB, see \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/ingest/duckdb\",children:\"Ingest data with DuckDB\"}),\". For more examples and source builds, see the \",(0,t.jsx)(e.a,{href:\"https://github.com/altertable-ai/duckdb-altertable\",children:\"DuckDB Altertable extension repository\"}),\".\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"For other DuckDB workflows, see the \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/integrations/duckdb\",children:\"DuckDB integration hub\"}),\".\"]})]})]})}function m(a={}){let{wrapper:e}=a.components||{};return e?(0,t.jsx)(e,{...a,children:(0,t.jsx)(u,{...a})}):u(a)}function s(a,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+a+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return x(S);})();\n;return Component;"},"_id":"docs/lakehouse/query/duckdb.mdx","_raw":{"sourceFilePath":"docs/lakehouse/query/duckdb.mdx","sourceFileName":"duckdb.mdx","sourceFileDir":"docs/lakehouse/query","contentType":"mdx","flattenedPath":"docs/lakehouse/query/duckdb"},"type":"Docs","path":"/lakehouse/query/duckdb","level":3,"parent":"lakehouse/query"}