PostgreSQL 18 reference · Math Functions

PostgreSQL LOG() Function

Return the base-10 logarithm of a number, or the logarithm in another base with log(b, x). log10() is a synonym.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

log(x)  |  log(b numeric, x numeric)  |  log10(x)

Parameters

ParameterDescription
b optional The base.
x A number (integer, numeric or double precision).

Return value

A number.

Examples

Different bases
SELECT log(1000) AS base10, log(2, 1024) AS base2;

Output

 base10 |        base2
--------+---------------------
      3 | 10.0000000000000000
(1 row)

Run this on your computer — see “Get Started” for setup.

Digits before the point
SELECT name, price, floor(log(price)) + 1 AS digits
FROM products
WHERE product_id IN (6, 8, 11);

Output

    name     | price  | digits
-------------+--------+--------
 4K Monitor  | 329.00 |      3
 Coffee Mug  |  12.00 |      2
 Rubber Duck |   5.50 |      1
(3 rows)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?