GRAPH clause causes empty result set

I have a non-empty database. I can see all of the data, if I query it like this:

select *
from <tag:stardog:api:context:all>
{ ?s ?p ?o }

However, I get no results if I try to get quads instead of triples using the following query:

select *
from <tag:stardog:api:context:all>
{ graph ?g { ?s ?p ?o } }

The problematic query produces the following plan, which is highly suspect:

From all
Slice(offset=0, limit=1000) [#1]
`─ Projection(?g, ?s, ?p, ?o) [#1]
   `─ Empty [#1]

Based on my reading of several older threads, it seems like this would be expected to produce all the quads in the database.

Is there another/correct way to query with a variable for the graph name?

Server version is 7.6.4.

The graphs that you see when you query over the default graph and named graphs are controlled by different clauses. You use FROM for the former and FROM NAMED for the latter.

You want:

select *
from named <tag:stardog:api:context:all>
{ graph ?g { ?s ?p ?o } }

or even simply:

select *
{ graph ?g { ?s ?p ?o } }

because the default dataset when no FROM or FROM NAMED is specified is equivalent to:

select *
from <tag:stardog:api:context:default>
from named <tag:stardog:api:context:all>
{ graph ?g { ?s ?p ?o } }

-Paul

We have this hot-off-the-press blog post in Stardog Labs that goes into the details of this topic.

-Paul

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.