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

# `shiftright` 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 `expr` bitwise signed right shifted by `n` bits. This function is a synonym for [`>>` (gt gt sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/gtgtsign.md).

## Syntax

```
shiftright(expr, n)
```

## Arguments

* `expr`: An `INTEGER` or `BIGINT` expression.
* `n`: An `INTEGER` expression specifying the number of bits to shift.

## Returns

The result type matches `expr`.

When `expr` is negative (that is, the most significant bit is set), the result remains negative because the function preserves the most significant bit.
The effective shift distance is `n` modulo 32 for an `INTEGER` `expr` and modulo 64 for a `BIGINT` `expr`.

## Examples

```sql
> SELECT shiftright(4, 1);
 2
> SELECT shiftright(-4, 1);
 -2
> SELECT shiftright(1, -1);
 0
> SELECT 4 >> 1;
 2
> SELECT -4 >> 1;
 -2
```

## Related functions

* [`>>` (gt gt sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/gtgtsign.md)
* [`shiftleft` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/shiftleft.md)
* [`shiftrightunsigned` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/shiftrightunsigned.md)
