Skip to main content
better-duck-diesel exposes DuckDB-specific SQL as a typed Diesel DSL — operators, scalar functions, and aggregates — so you reach DuckDB features that stock Diesel has no equivalent for without dropping to sql_query. Everything is verified against crates/better-duck-diesel/src/expressions/**; each item emits real DuckDB SQL and the Rust name matches the SQL name except where a #[sql_name] override is noted on its page.

Bringing in the prelude

Import the DSL alongside Diesel’s own prelude:
This adds:
  • Two operator extension traits — DuckTextExpressionMethods and DuckExpressionMethods — blanket-implemented for every expression, giving .ilike(), .glob(), .is_distinct_from(), and friends. See Operators.
  • A library of typed free functions — string, numeric, date/time, JSON, list/map, and more.
  • DuckDB aggregates defined with #[aggregate]. See Aggregates.
Do not invent functions beyond what these pages document — only the listed items are implemented. Calling an unlisted name will not compile.
Spatial ST_* functions are not in dsl::*. Import them from better_duck_diesel::spatial::* under feature = "spatial" — see Spatial.

Calling scalar functions

The free functions are ordinary Diesel expressions. Use them anywhere an expression is accepted — in .select(...), .filter(...), an UPDATE … SET, or standalone via diesel::select:
Each function’s argument and result SQL types are documented on its page; the Rust value types follow from those via Type mapping.

Calling aggregates

Aggregates are free functions too; use them in an aggregating or grouped .select:
See Aggregates. Diesel core already ships count/sum/avg/min/max; this crate adds only what core lacks.

Binding custom-typed values in an expression

Bare u64 / i128 / DuckUuid / … cannot be used directly as a DSL expression at a Duck* SQL type (a third-party coherence limit). Wrap them in a values::* newtype and .into_sql::<SqlType>():
The full newtype ↔ SQL-type list is on Type mapping.

The DSL pages

Operators

ILIKE / SIMILAR TO / GLOB / regex / null-safe comparison.

String functions

Case, trim, pad, search, similarity, regex, hashing, encoding.

Numeric & utility functions

Math, trig, conditional, UUID generation, version/typeof.

Date & time functions

Extract parts, build dates/times, format.

JSON functions

Validate, extract, and inspect JSON.

List & map functions

LIST and MAP scalar functions.

Aggregates

Statistical, approximate, bitwise, JSON aggregates.

Calling your own UDFs

Register #[duckdb_*] functions and call them typed.

Spatial

ST_* functions behind feature = "spatial".