Function Reference

LOG10

MySQL equivalent:

Returns the base-10 logarithm of a number.

PostgreSQL 17.5
LOG10(num)

Parameters

numnumeric | double precision
Positive number

Return value

A number of the same type as num (double precision or numeric); an error for 0 and negative numbers

Examples

Logarithm of 1000 and 0.01

PostgreSQL 17.5
SELECT LOG10(1000) AS log_1000,
	LOG10(0.01) AS log_hundredth;
log_1000log_hundredth
3-2.0000000000000000

Number of digits in a price

PostgreSQL 17.5
SELECT unit_price,
	FLOOR(LOG10(unit_price)) + 1 AS digits
FROM Payments
ORDER BY unit_price DESC
LIMIT 5;
unit_pricedigits
660005
100005
55004
22004
21004

Details

It is the same as LOG(num) with one argument. LOG10 is handy for counting the digits of a positive integer: FLOOR(LOG10(n)) + 1.

See also