I’m trying to invoke an N1QL UPDATE statement inside of an eventing function. The N1QL query works fine when invoked outside of the eventing procedure, but I am not able to deploy the eventing function because of a “SyntaxError: Unexpected template string”.
The issue seems to be, that the statement calls a user-defined function.
Aren’t user-defined functions supported in eventing N1QL statements?
My UPDATE statement looks like the following:
UPDATE t SET a[i].p = {"id": $meta.id, "rev": $meta.seq}
FOR i: s IN a WHEN s.b = $b END
WHERE ANY aa IN a SATISFIES aa.b = $b AND userDefinedFunction($meta.id) >= userDefinedFunction(aa.p.id) END ;
You must use $<variable> , as per N1QL specification, to use a JavaScript variable in the query statement. The object expressions for substitution are not supported and therefore you cannot use the meta.id expression in the query statement.
Instead of meta.id expression, you can use var id = meta.id in an N1QL query.
I think a small change as follows will fix your issue:
// You need to define local JavaScript variable to use in inline N1QL
var id = meta.id;
var seq = meta.seq;
UPDATE t SET a[i].p = {"id": $id, "rev": $seq}
FOR i: s IN a WHEN s.b = $b END
WHERE ANY aa IN a SATISFIES aa.b = $b AND userDefinedFunction($id) >= userDefinedFunction(aa.p.id) END ;
thanks for the hint. But unfortunately that doesn’t fix it.
As soon as I remove the userDefinedFunction() call I am able to deploy it, even when using the local $id variable.