0
votes

Why do I see return() at the end of an XQuery query?

e.g.

 let $updateIssues:=
     for $issue in fn:collection("InProgress_Audit")/ProductIssue
     return local:UpdateIssue($issue) 

 return ()
3

3 Answers

2
votes

It's not entirely clear what your question is. Given the way you've formulated it, possible answers include:

  • You see it because it's there.
  • You see it because someone typed it when they wrote the query.

Perhaps you mean 'why is it there?' Possible answers include:

  • It's there because without a return clause the FLWOR expression begun by the let clause is not complete.
  • It's there because the author of this query has a quirky sense of humor, and thought a four-line query was an amusing way to write an expression denoting the empty sequence (which can be more concisely written ()).
  • It's there because the author of the query wants you as a reader to know he'd really rather be writing C or Java or, really, any other programming language.
  • It's there because the author of the query finds it amusing that the return keyword in XQuery can be written to look like a function call. (The author may enjoy hazing newbies and practical jokes, too; approach with caution.)

Perhaps you mean "what does this query mean and how does it mean it?" Possible answers include:

  • The query returns the empty sequence.
  • The query takes the form of a FLWOR expression which defines a binding for the variable updateIssues (whose value is given by a nested FLWOR expression), and then returns () (that is, the empty sequence). Since nothing in the return clause depends on the value of updateIssues, there is no need for an XQuery engine to evaluate the expression used to specify the value (but there is also no guarantee that it won't do so -- processors are allowed to be smart about optimization but not required to be).
0
votes

In your example, the return () expression is the body of your let expression.

The assignment to $updateIssues is walking through a bunch of nodes, returning the value from a call to local:UpdateIssue(), and the sequence of those return values is being used as the variable value.

But, then, nothing is done with the variable and the function simply returns nothing to its caller.

I would be worried that an optimizing processor may choose to throw out the assignment because the variable being assigned isn't being used anywhere, but the processor you are using is likely not doing that if you are getting the update results you are expecting.

So, all that last line is doing is always returning an empty sequence as the value of the function when called.

0
votes

If I get your question right you are asking about return ().

return () means that you are returning a blank so in short you just want to assign the global variable to something and do not want to return anything from the function.

Else if you want to know the details on Return expression. It is a Part of XQuery FLWOR Expressions.

Being a functional language XQuery works on Functions.

For Loop, Let Loop, Where, Order By (FLWO) are all internally (inside XQuery Engine) acting as functions. Thus they all require a return after call to specify what needs to be the output from them.

If you require more information on XQuery functions you may refer the offical documentation.