Skip to main content

trunc

Function trunc 

Source
pub fn trunc<'a, V, E>(
    expr: E,
) -> SQLExpr<'a, V, <E::SQLType as RoundingPolicy<V::DialectMarker>>::Output, E::Nullable, E::Aggregate, E::Sources>
where V: SQLParam + 'a, V::DialectMarker: MathExt, E: Expr<'a, V>, E::SQLType: RoundingPolicy<V::DialectMarker>,
Expand description

Truncates toward zero.

Renders TRUNC(expr) on SQLite and PostgreSQL and TRUNCATE(expr, 0) on MySQL. The argument must be numeric. The result type comes from RoundingPolicy and keeps the argument’s nullability. On SQLite this needs the math feature (see MathExt).

§Examples

assert_eq!(
    trunc(users.score).sql(),
    r#"CAST (TRUNC ("users"."score") AS DOUBLE PRECISION)"#
);