0

To fetch all the triples from a named graph in my triplestore (OpenLink Virtuoso v6.1), I have written the SPARQL query:

SELECT ?s ?p ?o
WHERE {
    GRAPH eg:myGraph {
        ?s ?p ?o.
    }
}

But it seems I can't define the graph URI in the GRAPH declaration; the query doesn't return any triples.

If I use an intermediate variable ?g instead of the URI of my graph, the request works:

SELECT ?s ?p ?o
WHERE {
    FILTER(?g = eg:myGraph).
    GRAPH ?g {
        ?s ?p ?o.
    }
}

I don't see the difference between the two queries.

Is my first syntax a wrong query? Is this a subtlety of Virtuoso?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Thibaut Guirimand
  • 851
  • 10
  • 33
  • The two queries are equivalent. I also think the first is more efficient (generally speaking, because it has less variables). It must be a limitation/bug of the Virtuoso SPARQL parser. – enridaga May 05 '15 at 12:53
  • Does `select ... where { values ?g { eg:myGraph } graph ?g { ... } }` work? That might be more efficient than the filter, and makes it clearer that the value of ?g is supposed to have a predefined value. – Joshua Taylor May 05 '15 at 16:07
  • There is the same result as before `graph ?`. I've just seen that my version of virtuoso is the curent default version for debian : virtuoso 6.1 . Perhaps this problem is solved with virtuoso 7? – Thibaut Guirimand May 05 '15 at 16:13
  • SPARQL return an error on `values`. I think that the parser of this version just doesn't apply the curent SPARQL 1.1 specifications. – Thibaut Guirimand May 05 '15 at 16:22
  • You might need Virtuoso 7 – Joshua Taylor May 05 '15 at 18:56

1 Answers1

0

you can try to run

SELECT ?s ?p ?o
FROM NAMED eg:myGraph
WHERE {
    GRAPH eg:myGraph {
        ?s ?p ?o.
    }
}

or

SELECT ?s ?p ?o
FROM eg:myGraph
WHERE {
        ?s ?p ?o.
    }
ffa
  • 747
  • 1
  • 6
  • 14
  • Your first command return the right result (without '<' and '>') but second return the entire default graph. As said in the comments of the question, I think it is a problem in the version of virtuoso (unfortunately the last version working on the system I'm working on). – Thibaut Guirimand May 07 '15 at 08:02
  • yea I think that it mainly depends on which triple store you are using... with stardog they both work properly. If eg:myGraph wasn't intended to be a uri but a curie (which it is fairly obvious... I'm going to edit my answer) you don't need the <> – ffa May 07 '15 at 12:20