Thibaut Guirimand
Thibaut Guirimand

Reputation: 911

Why am I obliged to filter the graph URI in a SPARQL query?

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?

Upvotes: 0

Views: 434

Answers (1)

ffa
ffa

Reputation: 797

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.
    }

Upvotes: 0

Related Questions