--- name: motherduck-duckdb-sql description: Look up or repair DuckDB SQL syntax and verify MotherDuck-specific command and feature support. license: MIT --- # DuckDB SQL Reference for MotherDuck ## Source Of Truth - Prefer current DuckDB SQL docs for language features and function semantics. - Use current MotherDuck SQL docs for MotherDuck-only commands such as shares, secrets, snapshots, and Dive operations. - MotherDuck can lag upstream DuckDB releases for client compatibility; check MotherDuck version-lifecycle docs before promising newly released DuckDB syntax or types are available. - If the connection path matters, verify behavior against the current Postgres-endpoint docs before promising server-mode support. ## Default Posture - Write DuckDB SQL, not PostgreSQL SQL, even when the client connects through the Postgres endpoint. - Prefer fully qualified `"database"."schema"."table"` names; they are required once more than one database or share is attached. - Prefer DuckDB-native constructs when they simplify the query: `GROUP BY ALL`, `QUALIFY`, `UNION BY NAME`, `arg_max`, `EXCLUDE`, and `REPLACE`. - When porting SQL from another engine, translate functions, date arithmetic, identifier quoting, and type casts explicitly instead of assuming compatibility. - Verify current MotherDuck support before relying on recently released upstream DuckDB features such as `VARIANT`, native `GEOMETRY`, `MERGE INTO`, or `date_trunc` return-type changes. - Check whether the statement depends on local files, extension install/load, temporary-table behavior, or other client-only features before claiming it will work in MotherDuck. - Treat snapshot, restore, and `UNDROP DATABASE` statements as operational SQL with plan-specific retention behavior, not ordinary analytical syntax. - Treat `INCLUDE_PATTERN` as whole-table/view filtering on a Share. Row filters, hidden columns, and masking use share secure views (`WITH SECURE VIEW ... REPLACES