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

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/array/array-reverse-sort",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> Reference material for ARRAY_REVERSE_SORT function

# ARRAY_REVERSE_SORT

Returns the elements of the input array in descending order.

If the argument `<function>` is provided, the sorting order is determined by the result of applying `<function>` on each element of the array.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
ARRAY_REVERSE_SORT([<function>,] <array>)
```

## Parameters

| Parameter    | Description                                                  | Supported input type                                              |
| :----------- | :----------------------------------------------------------- | :---------------------------------------------------------------- |
| `<function>` | An optional function to be used to determine the sort order. | Any lambda function that takes the elements of `<array>` as input |
| `<array>`    | The array to be sorted.                                      | Any array                                                         |

## Return Type

`ARRAY` of the same type as the input array

## Example

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT
	ARRAY_REVERSE_SORT([ 4, 1, 3, 2 ]);
```

**Returns**: `[4,3,2,1]`

In this example below, the modulus operator is used to calculate the remainder on any odd numbers. Therefore `ARRAY_REVERSE_SORT` puts the lower (even) numbers last in the results.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT
	ARRAY_REVERSE_SORT(x -> x % 2, [ 4, 1, 3, 2 ]);
```

**Returns**: `[1,3,4,2]`
