{"title":"SQL engine","description":"Altertable uses DuckDB SQL for all queries, including federated queries across multiple data sources.","order":400,"askSuggestions":["How do I run Snowflake SQL without rewriting it?","What should I do when SQL transpilation fails?"],"navigation":true,"body":{"code":"var Component=(()=>{var g=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var D=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),T=(t,e)=>{for(var i in e)o(t,i,{get:e[i],enumerable:!0})},l=(t,e,i,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of f(e))!S.call(t,r)&&r!==i&&o(t,r,{get:()=>e[r],enumerable:!(a=m(e,r))||a.enumerable});return t};var w=(t,e,i)=>(i=t!=null?g(y(t)):{},l(e||!t||!t.__esModule?o(i,\"default\",{value:t,enumerable:!0}):i,t)),k=t=>l(o({},\"__esModule\",{value:!0}),t);var h=D((b,d)=>{d.exports=_jsx_runtime});var q={};T(q,{default:()=>p,frontmatter:()=>v});var n=w(h()),v={title:\"SQL engine\",description:\"Altertable uses DuckDB SQL for all queries, including federated queries across multiple data sources.\",order:400,askSuggestions:[\"How do I run Snowflake SQL without rewriting it?\",\"What should I do when SQL transpilation fails?\"]};function u(t){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",ol:\"ol\",p:\"p\",pre:\"pre\",strong:\"strong\",...t.components},{DocsCallout:i,DocsPreviewDocument:a,DocsPreviewSection:r,DocsTable:c}=e;return i||s(\"DocsCallout\",!0),a||s(\"DocsPreviewDocument\",!0),r||s(\"DocsPreviewSection\",!0),c||s(\"DocsTable\",!0),(0,n.jsxs)(a,{anchors:\"sql-engine dialect data-types federated-queries transpile-another-sql-dialect how-it-works common-source-dialects\",children:[(0,n.jsxs)(r,{sectionId:\"sql-engine\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"sql-engine\",children:\"SQL engine\"}),`\n`]}),(0,n.jsxs)(r,{sectionId:\"dialect\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"dialect\",children:\"Dialect\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Altertable uses the \",(0,n.jsx)(e.strong,{children:\"DuckDB SQL dialect\"}),\" for all queries. If you are familiar with PostgreSQL or SQLite, most core syntax will be familiar.\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Example query when Product Analytics is enabled for the environment:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT\n  distinct_id,\n  COUNT(*) AS sessions\nFROM product_analytics.analytics.web_sessions\nWHERE started_at >= date_trunc('week', now())\nGROUP BY distinct_id\nORDER BY sessions DESC\nLIMIT 10;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"For complete syntax reference, see the \",(0,n.jsx)(e.a,{href:\"https://duckdb.org/docs/sql/introduction\",children:\"DuckDB SQL Documentation\"}),\".\"]}),`\n`]}),(0,n.jsxs)(r,{sectionId:\"data-types\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,n.jsx)(e.h2,{id:\"data-types\",children:\"Data types\"}),`\n`,(0,n.jsx)(e.p,{children:\"Altertable supports the same data types as DuckDB, including:\"}),`\n`,(0,n.jsx)(c,{columns:[\"Category\",\"Types\"],data:[{Category:\"Numeric\",Types:\"`INTEGER`, `BIGINT`, `DOUBLE`, `DECIMAL`, `HUGEINT`\"},{Category:\"Text\",Types:\"`VARCHAR`, `TEXT`\"},{Category:\"Temporal\",Types:\"`DATE`, `TIMESTAMP`, `TIMESTAMPTZ`, `TIME`, `INTERVAL`\"},{Category:\"Binary\",Types:\"`BLOB`, `BITSTRING`\"},{Category:\"Boolean\",Types:\"`BOOLEAN`\"},{Category:\"Nested\",Types:\"`ARRAY`, `LIST`, `MAP`, `STRUCT`, `UNION`\"},{Category:\"Special\",Types:\"`UUID`, `JSON`\"}]}),`\n`,(0,n.jsxs)(e.p,{children:[\"For a complete list of supported data types and their specifications, see the \",(0,n.jsx)(e.a,{href:\"https://duckdb.org/docs/stable/sql/data_types/overview\",children:\"DuckDB Data Types Overview\"}),\".\"]}),`\n`]}),(0,n.jsxs)(r,{sectionId:\"federated-queries\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,n.jsx)(e.h2,{id:\"federated-queries\",children:\"Federated queries\"}),`\n`,(0,n.jsx)(e.p,{children:\"Connect multiple data sources, from BigQuery to Postgres catalogs, in the same SQL namespace:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT\n  u.email,\n  b.total_revenue\nFROM pg_production.users u\nJOIN bigquery.revenue b\n  ON u.id = b.user_id;\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"The engine handles cross-catalog federation automatically, optimizing query execution across all data sources in your lakehouse.\"}),`\n`]}),(0,n.jsxs)(r,{sectionId:\"transpile-another-sql-dialect\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,n.jsx)(e.h2,{id:\"transpile-another-sql-dialect\",children:\"Transpile another SQL dialect\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Altertable executes \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/sql-engine\",children:\"DuckDB SQL\"}),\". Most of the lakehouse\\u2014SQL Explorer, Postgres adapter, dashboards\\u2014assumes you write DuckDB syntax directly.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.code,{children:\"dialect\"}),\" parameter is different: it lets you send SQL written for another engine and have Altertable transpile it to DuckDB before execution. That is useful when you are porting saved queries from another platform, running BI-generated SQL, or prototyping a migration without rewriting every function by hand.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-json\",children:`{\n  \"statement\": \"SELECT DATEDIFF(day, start_date, end_date) AS days FROM my_catalog.main.orders\",\n  \"dialect\": \"snowflake\"\n}\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"Altertable transpiles the statement, then runs the DuckDB version on your catalog.\"}),`\n`]}),(0,n.jsxs)(r,{sectionId:\"how-it-works\",anchors:\"\",ancestors:\"transpile-another-sql-dialect\",index:\"5\",children:[(0,n.jsx)(e.h3,{id:\"how-it-works\",children:\"How it works\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"You send \",(0,n.jsx)(e.code,{children:\"statement\"}),\" in the source dialect and set \",(0,n.jsx)(e.code,{children:\"dialect\"}),\" to that engine.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Altertable transpiles the SQL to DuckDB using \",(0,n.jsx)(e.a,{href:\"https://github.com/tobilg/polyglot\",children:\"polyglot-sql\"}),\".\"]}),`\n`,(0,n.jsx)(e.li,{children:\"The transpiled statement runs on Workers like any other query.\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Omit \",(0,n.jsx)(e.code,{children:\"dialect\"}),\" (or write DuckDB SQL and leave it unset) when you already target DuckDB. Transpilation is optional, not the default path.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Dialect names are case-insensitive. Some engines accept aliases\\u2014for example, \",(0,n.jsx)(e.code,{children:\"tsql\"}),\", \",(0,n.jsx)(e.code,{children:\"mssql\"}),\", and \",(0,n.jsx)(e.code,{children:\"sqlserver\"}),\" all map to SQL Server.\"]}),`\n`]}),(0,n.jsxs)(r,{sectionId:\"common-source-dialects\",anchors:\"\",ancestors:\"transpile-another-sql-dialect\",index:\"6\",children:[(0,n.jsx)(e.h3,{id:\"common-source-dialects\",children:\"Common source dialects\"}),`\n`,(0,n.jsx)(e.p,{children:\"Transpilation coverage depends on the source dialect and the functions in your SQL. These are the engines teams most often port from:\"}),`\n`,(0,n.jsx)(c,{columns:[\"`dialect` value\",\"Source engine\"],data:[{\"`dialect` value\":\"`snowflake`\",\"Source engine\":\"Snowflake\"},{\"`dialect` value\":\"`databricks`\",\"Source engine\":\"Databricks\"},{\"`dialect` value\":\"`bigquery`\",\"Source engine\":\"Google BigQuery\"},{\"`dialect` value\":\"`spark`\",\"Source engine\":\"Apache Spark SQL\"},{\"`dialect` value\":\"`trino`\",\"Source engine\":\"Trino\"},{\"`dialect` value\":\"`presto`\",\"Source engine\":\"Presto\"},{\"`dialect` value\":\"`redshift`\",\"Source engine\":\"Amazon Redshift\"},{\"`dialect` value\":\"`postgresql`\",\"Source engine\":\"PostgreSQL\"},{\"`dialect` value\":\"`mysql`\",\"Source engine\":\"MySQL\"},{\"`dialect` value\":\"`tsql`\",\"Source engine\":\"Microsoft SQL Server\"},{\"`dialect` value\":\"`clickhouse`\",\"Source engine\":\"ClickHouse\"},{\"`dialect` value\":\"`athena`\",\"Source engine\":\"Amazon Athena\"}]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Many other dialects are supported, including \",(0,n.jsx)(e.code,{children:\"hive\"}),\", \",(0,n.jsx)(e.code,{children:\"oracle\"}),\", \",(0,n.jsx)(e.code,{children:\"sqlite\"}),\", \",(0,n.jsx)(e.code,{children:\"teradata\"}),\", and \",(0,n.jsx)(e.code,{children:\"fabric\"}),\". Unknown dialect names return \",(0,n.jsx)(e.code,{children:\"400 Bad Request\"}),\".\"]}),`\n`,(0,n.jsxs)(i,{title:\"Transpilation limits\",children:[(0,n.jsx)(e.p,{children:\"Transpilation handles common syntax and function differences, but it is not a full semantic rewrite. Warehouse-specific UDFs, session variables, staged files, and engine-only table functions may fail to transpile or behave differently after conversion.\"}),(0,n.jsxs)(e.p,{children:[\"When transpilation fails, the API returns \",(0,n.jsx)(e.code,{children:\"400 Bad Request\"}),\" with an error such as \",(0,n.jsx)(e.code,{children:\"Failed to transpile <source engine> SQL to DuckDB\"}),\". Fix the statement, simplify it, or rewrite the incompatible parts in DuckDB SQL.\"]}),(0,n.jsx)(e.p,{children:\"For production workloads, treat transpilation as a migration shortcut: validate results against the source engine, then commit to DuckDB-native SQL where performance and clarity matter.\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Check the \",(0,n.jsx)(e.a,{href:\"/docs/api-references/lakehouse#post-query\",children:\"query API reference\"}),\" for the complete request shape and all supported parameters.\"]})]})]})}function p(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(t)}function s(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return k(q);})();\n;return Component;"},"_id":"docs/lakehouse/sql-engine.mdx","_raw":{"sourceFilePath":"docs/lakehouse/sql-engine.mdx","sourceFileName":"sql-engine.mdx","sourceFileDir":"docs/lakehouse","contentType":"mdx","flattenedPath":"docs/lakehouse/sql-engine"},"type":"Docs","path":"/lakehouse/sql-engine","level":2,"parent":"lakehouse"}