Even Friendlier SQL with DuckDB
DuckDB extends SQL syntax with features that simplify everyday queries and enable dynamic analysis. Additions include reusable column aliases within a SELECT, COLUMNS() for selecting and transforming columns by regex, EXCLUDE/REPLACE or lambda, automatic JSON-to-nested-type conversion with dot notation, FROM-first queries, dot-operator function chaining, UNION/INSERT BY NAME, and dynamic PIVOT/UNPIVOT that need no hardcoded column values. Each feature is shown next to the verbose standard-SQL equivalent it replaces.
Related posts
- Gems of DuckDB 2.0.0
DuckDB mediumAdeptDuckDB 2.0.0 LTS includes a set of smaller features beyond its headline items. The Python client gains an appender for buffered row inserts, though INSERT INTO ... SELECT remains faster for DataFrames and Arrow tables. The CLI adds pretty-printed .schema, a .manual function reference, calculator-style expressions and queryable command history via shell_history(). New SQL features include SHOW for settings, CREATE SECURE VIEW to hide statistics and plans, regexp_extract options, setval for sequences, session variables as prepared-statement defaults, custom PARTITION_PATH and ORDER_BY in COPY, GeoJSON writing, and extension-defined window functions.
- Ducks in a Column
DuckDB mediumAdeptDuckDB stores data by column and processes it in vectors of 2,048 values, which drives its compression, projection pushdown and aggregation speed. A tour built on a duck-sightings dataset shows querying CSV, Parquet, S3 and Hive-partitioned files in place (with zonemap row-group skipping and CSV type sniffing), column-level friendly SQL (EXCLUDE, REPLACE, COLUMNS() with regex or lambdas, FROM-first, STRUCT unpacking, SUMMARIZE), and aggregation shortcuts such as GROUP BY ALL, FILTER, arg_max, PIVOT/UNPIVOT and approximate aggregates. Window functions, QUALIFY, ASOF joins for aligning mismatched time series, and list aggregation round out the examples.
- SQL or NoSQL? Why not use both (with PostgreSQL)?
Supabase mediumAdeptPostgreSQL's JSONB columns let an app store nested, variable-length data (here, a daily food, water and exercise log) as a single row instead of spreading it across several normalized tables, while keeping SQL available for analysis. A worked example builds a calendar table with JSONB log fields and inserts a whole day in one statement. It then uses jsonb_array_elements with the -> and ->> operators to flatten the arrays into rows. Because aggregates cannot wrap set-returning functions, the flattened query goes into a CTE before summing daily calories or filtering for specific items.
- DuckDB: analyze 50,000+ datasets stored on the Hugging Face Hub
Hugging Face mediumAdeptEvery public dataset on the Hugging Face Hub is now automatically converted to Parquet by the dataset viewer and can be queried with SQL through DuckDB. Parquet file URLs come from the datasets-server `/parquet` HTTP endpoint, and DuckDB's `httpfs` extension then runs analytical queries directly against those remote files. Large datasets are sharded into 500MB Parquet chunks, which DuckDB can query together as multiple files.
- DuckDB Tricks – Part 1
DuckDB mediumAdeptFive DuckDB SQL tricks for interactive use, built around a small example CSV and DuckDB's friendly SQL shorthands such as FROM-first syntax. Casting to DECIMAL(15, 3) pretty-prints floats while keeping them numeric, unlike printf. CREATE TABLE ... AS FROM ... LIMIT 0 copies a schema without data, and ORDER BY hash(rowid + 42) gives a deterministic shuffle (the offset matters because hash(0) is 0). The read_csv types argument overrides auto-detected column types, and COPY can rewrite a CSV in place, which a naive Unix shell redirect cannot do.