Syntax
Parameters
-
array: The array from which to extract the top-n elements. The array can contain elements of any comparable data type supported by the database. -
count: The number of top elements to return. It must be a non-negative integer.
Return value
Returns an array containing the top-n elements from the input array, sorted in descending order. The data type of the return value is the same ARRAY type as the input array.Usage notes
- Elements are sorted in descending order according to their natural ordering.
- If
countis 0 or negative, an empty array is returned. - If
countis larger than the array size, the entire array, sorted in descending order, is returned. - If the input
arrayorcountis NULL, the result is NULL. - NULL elements within the array are considered smaller than any non-NULL value and will appear at the end if included in the result.
Examples
Example 1: Get the top 3 elements from an integer array.count is larger than the array length).
count is 0.