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>where
V: SQLParam + 'a,
V::DialectMarker: PostgresDateTimeSupport,
S: Expr<'a, V>,
E: Expr<'a, V>,
E::SQLType: Temporal,
O: Expr<'a, V>,
O::SQLType: Temporal,
S::Nullable: NullOr<E::Nullable>,
E::Nullable: Nullability,
<S::Nullable as NullOr<E::Nullable>>::Output: NullOr<O::Nullable>,
O::Nullable: Nullability,
S::Aggregate: AggOr<E::Aggregate>,
<S::Aggregate as AggOr<E::Aggregate>>::Output: AggOr<O::Aggregate>,
O::Aggregate: AggregateKind,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");