---
title: mod function
description: Learn the syntax of the mod function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/mod
---

# `mod` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the remainder after `dividend / divisor`. This function is equivalent to the [`%` (percent sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/percentsign.md).

## Syntax

```
mod(dividend, divisor)
```

## Arguments

* `dividend`: An expression that evaluates to a numeric.
* `divisor`: An expression that evaluates to a numeric.

## Returns

If both `dividend` and `divisor` are of `DECIMAL`, the result matches the divisor's type.
In all other cases, a `DOUBLE`.

If `divisor` is 0, the function raises a [REMAINDER\_BY\_ZERO](https://docs.databricks.com/aws/en/error-messages/error-classes.md#remainder_by_zero) error.
To return `NULL` instead, use the [try\_mod()](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_mod.md) function.

## Common error conditions

* [REMAINDER\_BY\_ZERO](https://docs.databricks.com/aws/en/error-messages/error-classes.md#remainder_by_zero)

## Examples

```sql
> SELECT mod(2, 1.8);
 0.2

> SELECT mod(2, 0);
 Error: REMAINDER_BY_ZERO
```

## Related functions

* [`%` (percent sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/percentsign.md)
* [`/` (slash sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/slashsign.md)
* [`pmod` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/pmod.md)
* [`try_mod` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_mod.md)
