Hi Kristian,
The function position() returns the current context position. The context position is only assigned by certain expressions, such as the filter expression:
(1 to 10)[position() = (1 to 3)]
Before the predicate is evaluated, the current context position will be assigned for each result item of $expr.
If you use position() outside a predicate, it’s usually undefined, and if you call position(), you get an XPDY0002 error in return. The same applies to FLWOR expressions: The following query raises the same error:
for $i in 1 to 10 where position() = (1 to 3) return $i
It’s interesting to read that your second query is not rejected; I assume that the where clause is optimized away at compile time. Feel free to send me the output of the Info View panel, maybe I can see what’s going on.
Best, Christian
- Unexpected behaviour, returns 21 records
let $file := db:list("Snomed")[matches(.,"MRCM")][3] return for $record in (db:open("Snomed", $file)/csv/record) where position() = (1 to 3) return $record
I have highlighted the one line that differs between them, e.g the first uses the positional predicate in a path expression and the second uses it in a where clause.
Best regards, Kristian Kankainen