#32 sum() function in predicates

v6.4.4
closed
Michael Kay
5
2012-10-08
2001-09-21
Michael Kay
No

When the sum() function is used inside a predicate,
and the predicate also contains a variable reference,
then the sum() function will give the wrong answer.

Example: order[sum(item/@price) > $limit]

This is a bug in the expression reduction that occurs
when a predicate contains a variable (or some other
conditions, e.g. a call on current()). It also happens
in some contexts other than predicates, for example
sort keys. The sum() function is wrongly rewritten,
and thus evaluated, as a count() function.

Present in all previous releases.
Spotted by MHK when reading the code!
Raised 2001-09-20

Discussion

  • Michael Kay
    Michael Kay
    2001-11-15

    Logged In: YES
    user_id=251681

    Fixed in 6.5