I cannot get avg() or sum() to work, although min() and max() work fine.
Take a look at the following code:
{let $a := avg($subquery//count) return
{$a}
}
This produces a ‘Runtime type exception’, as does sum(). But if I use min() or max(), it works fine.
Can someone tell me what I am doing wrong?
Hi Simon,
min() and max() differ from avg() and sum() in that they just
require the type of its argument list entries to be sortable,
whereas for avg()and sum() the arguments must also allow for a
certain kind of arithmetic. Since your example works with min()
and max() and not for avg() and sum() the entries of the argument
list are obviously of a sortable type but not able to be added
up. Most likely they are strings. Try change your Tamino Schema
definition to define the count field as, say, integer or use the
number() function as follows:
avg(for $x in $subquery//count
return number($x))
regards,
Juliane.