GREATEST

Syntex

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

# 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 
----------
         

Last updated