pub fn date_bin<'a, V, S, E, O>(
stride: S,
source: E,
origin: O,
) -> SQLExpr<'a, V, E::SQLType, <<S::Nullable as Nullability>::Or<E::Nullable> as Nullability>::Or<O::Nullable>, <<S::Aggregate as AggregateKind>::Or<E::Aggregate> as AggregateKind>::Or<O::Aggregate>, (S::Sources, (E::Sources, O::Sources))>where
V: SQLParam + 'a,
V::DialectMarker: DialectSupports<PostgresDateTime>,
S: Expr<'a, V>,
E: Expr<'a, V>,
E::SQLType: Temporal,
O: Expr<'a, V>,
O::SQLType: Temporal,
E::Nullable: Nullability,
O::Nullable: Nullability,
O::Aggregate: AggregateKind,Expand description
Rounds a timestamp down into fixed-size buckets (DATE_BIN), on PostgreSQL 14+.
Buckets are stride wide (an interval as text, such as '15 minutes') and
start at origin. source and origin must be temporal. The stride is
cast to INTERVAL. The result has source’s type and is nullable if any
argument is.
§Examples
let bucket = date_bin("15 minutes", users.created_at, localtimestamp());
assert_eq!(
bucket.sql(),
r#"DATE_BIN (CAST ($1 AS INTERVAL), "users"."created_at", LOCALTIMESTAMP)"#
);