Skip to main content

log2

Function log2 

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

Base-2 logarithm (LOG2), on SQLite and MySQL.

The argument must be numeric. The result is the dialect’s double type and always nullable, since both dialects return NULL outside the domain. SQLite needs the math feature. PostgreSQL has no LOG2, so this does not compile for PostgreSQL; use log with base 2 there.

§Examples

assert_eq!(log2(users.score).sql(), "LOG2(`users`.`score`)");