# gamma

> 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: gamma
latest-operator-version: v26.2.4
latest-console-tag: v3.12.0
latest-connect-version: 4.113.1
latest-redpanda-tag: v26.2.4
docname: sql/sql-functions/math-functions/gamma
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/gamma.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/math-functions/gamma.adoc
description: The `gamma()` function returns the gamma function of a number, extending the factorial to real numbers.
page-topic-type: reference
page-git-created-date: "2026-09-14"
page-git-modified-date: "2026-09-14"
---

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

The `gamma()` function returns the gamma function of a given number. The gamma function extends the factorial to real numbers: for a positive integer _n_, `gamma(n)` equals (_n_ - 1)!.

## [](#syntax)Syntax

```sql
GAMMA(number)
```

## [](#arguments)Arguments

-   `number`: A required `double precision` value. `gamma()` accepts `real` values and computes them as `double precision`.


## [](#return-type)Return type

`gamma()` returns a `double precision` value, or `NULL` if the argument is `NULL`. If the result cannot be represented as a `double precision` value, `gamma()` returns an error instead. See [Out-of-range inputs](#out-of-range-inputs).

## [](#examples)Examples

These examples show how to use the `gamma()` function.

### [](#gamma-of-a-positive-integer)Gamma of a positive integer

For a positive integer _n_, `gamma(n)` equals (_n_ - 1)!, so `gamma(5)` equals `4! = 24`:

```sql
SELECT gamma(5);
```

```sql
 gamma
-------
    24
(1 row)
```

### [](#gamma-of-a-fractional-value)Gamma of a fractional value

For non-integer inputs, `gamma()` returns a fractional result. For example, `gamma(0.5)` returns the square root of pi (approximately `1.772`).

## [](#out-of-range-inputs)Out-of-range inputs

The gamma function is undefined or unrepresentable for some inputs. In these cases `gamma()` returns an error rather than infinity or `NaN`:

-   Zero and the negative integers are poles of the gamma function. `gamma(0)` and, for example, `gamma(-2)` fail with:

    ```sql
    value out of range: overflow
    ```

-   Inputs whose result is too large for `double precision` fail with the same `value out of range: overflow` error. The largest integer with a representable result is `171`, so `gamma(172)` overflows.

-   Large negative, non-integer inputs whose result is too small to represent fail with:

    ```sql
    value out of range: underflow
    ```


For the special floating-point values, `gamma()` returns `NaN` for `NaN` and positive infinity for positive infinity. Negative infinity fails with `value out of range: overflow`.