fn:max function

The fn:max function returns the maximum of the values in a sequence.

Syntax

Read syntax diagramSkip visual syntax diagramfn:max( sequence-expression)
sequence-expression
The empty sequence, or a sequence in which all of the items are one of the following types:
  • Numeric
  • String
  • xs:date
  • xs:dateTime
  • xs:time
  • xs:dayTimeDuration
  • xs:yearMonthDuration

Input items of type xs:untypedAtomic are cast to xs:double. Numeric input items are converted to the least common type that can be compared by a combination of type promotion and subtype substitution.

Returned value

If sequence-expression is not the empty sequence, the returned value is a value of type xs:anyAtomicType that is the maximum of the values in sequence-expression. The data type of the returned value is the same as the data type of the items in sequence-expression, or the common data type to which the items in sequence-expression are promoted.

If sequence-expression contains one item, that item is returned. If sequence-expression is the empty sequence, the empty sequence is returned. If the sequence includes the value NaN, NaN is returned.

Example

The following query returns a single row that contains a value of type double that is the maximum of the sequence (500, 1.0E2, 40.5).

SELECT * FROM 
 XMLTABLE (XMLNAMESPACES (DEFAULT 'http://posample.org'), 
           '$d'  
           PASSING XMLPARSE(DOCUMENT '<x xmlns="http://posample.org">
                             <b>500</b><b>1.0E2</b><b>40.5</b></x>') AS "d"
           COLUMNS RES DOUBLE PATH 'fn:max(x/b)') X                                               

The values are promoted to the xs:double data type. The function returns the xs:double value 5.0E2, which is then converted to the SQL double data type.