> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# FACTORIAL

> Returns the factorial of an integer.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

NULL input or an input outside 0 through 20 returns NULL. factorial(0) is 1.

## Syntax

### Integer (scalar)

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
factorial(value)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | BIGINT | Yes | Integer expression whose factorial is computed. 0 through 20; other integer values return NULL. |

## Returns

* Type: BIGINT
* Possible values: 1 through 2432902008176640000 for supported integer inputs.
* NULL behavior: NULL input or an input outside 0 through 20 returns NULL. factorial(0) is 1.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Numeric input is converted to BIGINT. Use an explicit BIGINT cast when the conversion affects your result.

## Examples

### Basic call

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT factorial(5) AS result;
```

| result |
| - |
| 120 |

### Zero and upper boundary

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT factorial(0) AS zero_value, factorial(20) AS upper_value;
```

| zero\_value | upper\_value |
| - | - |
| 1 | 2432902008176640000 |

### NULL and out-of-range inputs

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT factorial(CAST(NULL AS BIGINT)) AS null_value, factorial(-1) AS negative_value, factorial(21) AS overflow_value;
```

| null\_value | negative\_value | overflow\_value |
| - | - | - |
| NULL | NULL | NULL |

## Limitations

* Only the factorials of integers from 0 through 20 fit the supported range. Negative inputs and values above 20 produce NULL.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.