# log

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: log
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/math-functions/log
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/math-functions/log.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/math-functions/log.adoc
description: The `log()` function returns the base-10 logarithm or logarithm of the specified base of a given number.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/math-functions/log.md -->

The `log()` function returns the base-10 logarithm or logarithm of the specified base of a given number.

## [](#syntax)Syntax

This example illustrates the syntax of the `log()` function:

```sql
-- base-10 logarithm
LOG(number)

-- logarithm of number
LOG(base, number)
```

Where:

-   `base`: The base number. It must be greater than 0 and not equal to 1.

-   `number`: The number logarithm to obtain. It must be a positive number and greater than 0.


## [](#examples)Examples

### [](#base-10-logarithm)Base-10 logarithm

#### [](#basic-usage)Basic usage

In this case, the `log()` function calculates the base-10 logarithm of a specified number.

```sql
SELECT LOG(2), LOG(2.5);
```

The query returns:

```sql
        log         |   log
--------------------+---------
 0.3010299956639812 | 0.39794
```

#### [](#negative-value)Negative value

In this example, the `log()` function is applied to negative numbers.

```sql
SELECT LOG(-1);
```

Any input of negative values returns a `NaN` result.

```sql
 log
-----
 NaN
```

#### [](#null-value)NULL value

The `log()` function will return `NULL` if the argument is `NULL`.

```sql
SELECT LOG(NULL);
```

A null result is returned when an argument passed is null.

```sql
 log
-----
```

#### [](#zero-value)Zero value

In this example, the `log()` takes zero as an argument.

```sql
SELECT LOG(0);
```

The query returns:

```sql
    log
-----------
 -Infinity
```

### [](#logarithm-with-custom-base)Logarithm with custom base

#### [](#basic-usage-2)Basic usage

In this case, the `log()` function calculates the logarithm of a specified number.

```sql
SELECT LOG(4, 16),
       LOG(0.7, 0.8),
       LOG(0.5, 10),
       LOG(1, NULL);
```

The query returns:

```sql
 log |    log     |    log    | log
-----+------------+-----------+-----
   2 | 0.62562156 | -3.321928 |
```

#### [](#use-with-a-table)Use with a table

Consider a database table called **_data_** with the records:

```sql
CREATE TABLE data (
    data_column TEXT,
    x REAL,
    y REAL
);

INSERT INTO data (data_column, x, y) VALUES
('Data 1', 0.5, 2),
('Data 2', 1, 2),
('Data 3', 5, 2),
('Data 4', 10, 10),
('Data 5', 50, 10);

SELECT * FROM data;
```

```sql
 data_column |  x  | y
-------------+-----+----
 Data 1      | 0.5 |  2
 Data 2      |   1 |  2
 Data 3      |   5 |  2
 Data 4      |  10 | 10
 Data 5      |  50 | 10
```

Use the `log()` function to calculate the logarithm of column **_y_** (as a base) and column _x_ (as a number):

```sql
SELECT *, LOG(y, x) AS LOG_Value FROM data;
```

The query returns:

```sql
 data_column |  x  | y  | log_value
-------------+-----+----+-----------
 Data 1      | 0.5 |  2 |        -1
 Data 2      |   1 |  2 |         0
 Data 3      |   5 |  2 |  2.321928
 Data 4      |  10 | 10 |         1
 Data 5      |  50 | 10 |   1.69897
```