# GREATEST

## Syntex

```sql
GREATEST
(
  expr1       IN anynonarray,
  expr_array  IN variadic anyarray
)
RETURNS anynonarray;
```

## Overview

The GREATEST function returns the largest value among the passed in arguments. If any of the arguments are NULL, the entire result will be NULL.

The PostgreSQL default function returns NULL only if all arguments are NULL, whereas this function returns NULL if even one is NULL.

#### Parameters

| Parameter   | Description                                                                                                                                                                                  |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| expr1       | `anynonarray` type: the first value to compare. It must be non-NULL.                                                                                                                         |
| expr\_array | `variadic anyarray` type: an array containing additional arguments. If there is a NULL in the array, the entire result is NULL. Each element of the array must be of the same type as expr1. |

## Example

```sql
# test 1
SELECT oracle.GREATEST(5, 3, 9);

 greatest 
----------
        9
(1 row)

# test 2
SELECT oracle.GREATEST('apple'::text, 'banana', 'cherry'); -- result: cherry (Compare strings alphabetically)

 greatest 
----------
 cherry
(1 row)

# test 3
SELECT oracle.GREATEST(10, NULL, 7); -- result NULL

 greatest 
----------
         
```

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tibero.com/tmaxopensql.en/tmax-o2-extensions/reference-guides/sql-function/conditional-functions/greatest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
