Understanding Variable Scoping in SPARQL Graph Patterns
SPARQL question: It appears that variables can't cross graph pattern boundaries. This doesn't work (Error 400: Bad Request):
WHERE {
?s :p1 ?o1 ;
:p2 ?o2 .
?o1 :p3 ?o3 .
OPTIONAL {
?o2 :p4 "some literal"
}
}i.e., ?o2 seemingly can't cross the OPTIONAL boundary. This does work:
WHERE {
?s :p1 ?o1 .
?o1 :p3 ?o3 .
OPTIONAL {
?s :p1 ?o2 .
?o2 :p4 "some literal" .
}
}I had to both remove any reference to ?o2 in the main body of the WHERE clause and repeat the s :p1 part in the OPTIONAL clause. Is this because the basic graph pattern and optional graph pattern are completely separate (as far as variable scoping)?