Search Shortcut cmd + k | ctrl + k
Search cmd+k ctrl+k
Dark Mode
1.1 (stable)
Friendly SQL

DuckDB offers several advanced SQL features as well syntactic sugar to make SQL queries more concise. We call these colloquially as “friendly SQL”.

Several of these features are also supported in other systems while some are (currently) exclusive to DuckDB.

Clauses

  • Creating tables and inserting data:
  • Describing tables and computing statistics:
    • DESCRIBE: this clause provides a succinct summary of the schema of a table or query.
    • SUMMARIZE: this clause returns summary statistics for a table or query.
  • Making SQL clauses more compact:
    • FROM-first syntax with an optional SELECT clause: DuckDB allows queries in the form of FROM tbl which selects all columns (performing a SELECT * statement).
    • GROUP BY ALL: this clause allows omitting the group-by columns by inferring them from the list of attributes in the SELECT clause.
    • ORDER BY ALL: this clause allows ordering on all columns (e.g., to ensure deterministic results).
    • SELECT * EXCLUDE: the EXCLUDE option allows excluding specific columns from the * expression.
    • SELECT * REPLACE: the REPLACE option allows replacing specific columns with different expressions in a * expression.
    • UNION BY NAME: this clause performing the UNION operation along the names of columns (instead of relying on positions).
  • Transforming tables:
    • PIVOT to turn long tables to wide tables.
    • UNPIVOT to turn wide tables to long tables.
  • Defining SQL-level variables:

Query Features

Literals and Identifiers

Data Types

Data Import

Functions and Expressions

Join Types

Trailing Commas

DuckDB allows trailing commas, both when listing entities (e.g., column and table names) and when constructing LIST items. For example, the following query works:

SELECT
    42 AS x,
    ['a', 'b', 'c',] AS y,
    'hello world' AS z,
;