Skip to main content

date_bin

Function date_bin 

Source
pub fn date_bin<'a, V, S, E, O>(
    stride: S,
    source: E,
    origin: O,
) -> SQLExpr<'a, V, E::SQLType, <<S::Nullable as NullOr<E::Nullable>>::Output as NullOr<O::Nullable>>::Output, <<S::Aggregate as AggOr<E::Aggregate>>::Output as AggOr<O::Aggregate>>::Output>
Expand description

DATE_BIN - bins timestamps into intervals (PostgreSQL 14+).

Rounds a timestamp down to the nearest multiple of stride from origin. Useful for time-series bucketing.

ยงExample

use drizzle_core::expr::date_bin;

// SELECT DATE_BIN('15 minutes', events.created_at, TIMESTAMP '2001-01-01')
let bucketed = date_bin("15 minutes", events.created_at, "2001-01-01");