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;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;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.