Loading TOC...

MarkLogic 12 EA 2 Product Documentation
fn:distinct-values

fn:distinct-values(
   $arg as item()*,
   [$collation as xs:string]
) as xs:anyAtomicType*

Summary

Returns the sequence that results from removing from $arg all but one of a set of values that are eq to one other. Values that cannot be compared, i.e. the eq operator is not defined for their types, are considered to be distinct. Values of type xs:untypedAtomic are compared as if they were of type xs:string. The order in which the sequence of values is returned is implementation dependent.

The static type of the result is a sequence of prime types as defined in Section 7.2.7 The fn:distinct-values function[FS].

The collation used by the invocation of this function is determined according to the rules in 7.3.1 Collations. The collation is used when string comparison is required.

If $arg is the empty sequence, the empty sequence is returned.

For xs:float and xs:double values, positive zero is equal to negative zero and, although NaN does not equal itself, if $arg contains multiple NaN values a single NaN is returned.

If xs:dateTime, xs:date or xs:time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Note that xs:dateTime, xs:date or xs:time values can compare equal even if their timezones are different.

Which value of a set of values that compare equal is returned is implementation dependent.

Parameters
$arg A sequence of items.
collation The optional name of a valid collation URI. For information on the collation URI syntax, see the Search Developer's Guide.

Example

fn:distinct-values((1, 2.0, 3, 2)) might return (1, 3, 2.0).

The following query:

let $x as xs:untypedAtomic*
    := (xs:untypedAtomic("cherry"),
        xs:untypedAtomic("bar"),
        xs:untypedAtomic("bar"))
return fn:distinct-values ($x)
                                   
returns a sequence containing two items ("cherry", "bar")
of type xs:untypedAtomic.

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.