S02051

Error Code

S02051

Error Message

Row reduction operation <xxx> cannot be used with PIVOT BY clause within an EXEC statement. RefId: S02051

Probable Causes

When used with pivot by, theexec statement generates a matrix. This error occurs when applying row-based functions to the returned matrix. For example:
def createMyTable(n) {
    intv = take(1..10, n)
    symbol = take(`a`b`c, n)
    id = rand(100, n)
    strv = take("abs" + string(1..10), n)
    doublev = rand(10.0, n)
    return table(intv, strv, doublev, id, symbol)
}

n = 100
t = createMyTable(n)

EXEC rowSum(doublev) FROM t PIVOT BY id, symbol => Row reduction operation "rowSum" cannot be used with PIVOT BY clause within an EXEC statement.

Solutions

Replace the exec statement with the following select statement, which returns a table. The returned table can be converted to a matrix if needed.
SELECT rowSum(doublev) FROM t PIVOT BY id, symbol