Skip to main content

sqrt

Function sqrt 

Source
pub fn sqrt<'a, V, E>(
    expr: E,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Double, <V::DialectMarker as DialectTypes>::DomainNullable<E::Nullable>, E::Aggregate, E::Sources>
where V: SQLParam + 'a, V::DialectMarker: MathExt, E: Expr<'a, V>, E::SQLType: Numeric,
Expand description

Square root (SQRT).

The argument must be numeric. The result is the dialect’s double type. On SQLite and MySQL a negative argument gives NULL, so the result is nullable there; PostgreSQL raises an error instead and keeps the argument’s nullability. On SQLite this needs the math feature.

§Examples

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