Skip to main content

log

Function log 

Source
pub fn log<'a, V, E1, E2>(
    base: E1,
    value: E2,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Double, <V::DialectMarker as DialectTypes>::DomainNullable<<E1::Nullable as Nullability>::Or<E2::Nullable>>, <E1::Aggregate as AggregateKind>::Or<E2::Aggregate>, (E1::Sources, E2::Sources)>
where V: SQLParam + 'a, V::DialectMarker: MathExt, E1: Expr<'a, V>, E1::SQLType: Numeric, E2: Expr<'a, V>, E2::SQLType: Numeric, E2::Nullable: Nullability,
Expand description

Logarithm of value in base base (LOG(base, value)).

Both arguments must be numeric. The result is the dialect’s double type. It is nullable if either argument is, and always nullable on SQLite and MySQL, which return NULL outside the domain. On PostgreSQL both arguments are cast to NUMERIC, since only LOG(numeric, numeric) exists there. On SQLite this needs the math feature.

§Examples

assert_eq!(
    log(2, users.score).sql(),
    r#"CAST (LOG (CAST ($1 AS NUMERIC), CAST ("users"."score" AS NUMERIC)) AS DOUBLE PRECISION)"#
);