hi I have a bit lame question, can’t find the answer though.
what happens if I leave the constructor brackets void?
e.g.
{data(doc("somedata.xml")//node[0])}
I mean, I know what happens, but what is it considered as when being parsed?
is it like ?
{
for $i in "0"
return
data(doc("somedata.xml")//node[0])
}
It is a common misconception that any XQuery is a FLWOR expression. This misconception comes when people approach XQuery from a SQL perspective, treating it as a SELECT.
This is in fact not the case; a FLWOR expression is in many ways just another expression. It may be that a FLWOR expression is executed as a SQL expression, but this doesn’t have to be the case.
XQuery can be viewed as a functional programming language (like Haskell) that happens to have some declarative constructs (like where and order by).
The expression
1+2is just an XQuery expression that adds the numbers 1 and 2, there does not need to be an implicit FLWOR expression around it.If you wanted to consider XQuery in a fully tuple-based algebra then you could consider the input to be a single empty tuple. By this I mean the following.
Look at this query:
If you were considering this in a tuple based algebra, the input to the for expression would be a stream of tuples defining
$xand$y. It is obvious how this could relate to a database query. This corresponds to a table with two columns$xand$yand a row for each pair that have equal names.You could consider the following query
as operating on a single tuple with no values. This would be a little bit like a FLWOR expression with no fors or lets (just a return expression, if that were allowed). In relational land this would be a table with no columns and one row. However this is just a logical abstraction, and most (if not all) XQuery implementations represent this as just an expression.