user1269298
user1269298

Reputation: 727

How to calculate base 2 logarithm of a number in Redshift

There are log10 and ln function in manual, but can not find how to compute log2 anymore ..

https://docs.aws.amazon.com/redshift/latest/dg/Math_functions.html

Upvotes: 3

Views: 1015

Answers (2)

The Impaler
The Impaler

Reputation: 48865

Per math classes in high school:

log2(n) ::= log10(n) / log10(2)

any base will do. You can do it with base e too, as in:

log2(n) ::= ln(n) / ln(2)

Upvotes: 3

Gordon Linoff
Gordon Linoff

Reputation: 1270893

The log in any base can be calculated by division. For this particular case:

select ln(x) / ln(2)

Upvotes: 7

Related Questions