# GRAPH clause causes empty result set

**URL:** <https://community.stardog.com/t/graph-clause-causes-empty-result-set/3116>\
**Category:** Support\
**Created:** [June 28, 2021, 12:40am UTC](https://community.stardog.com/t/graph-clause-causes-empty-result-set/3116 "2021-06-28T00:40:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Bloom](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/brandon_bloom/32/1017_2.png) [@Brandon\_Bloom](https://community.stardog.com/u/Brandon_Bloom)\
**Post date:** [June 28, 2021, 12:40am UTC](https://community.stardog.com/t/graph-clause-causes-empty-result-set/3116/1 "2021-06-28T00:40:26Z")

</div>

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

```auto
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:

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

```

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![PaulJackson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pauljackson/32/243_2.png) [@PaulJackson](https://community.stardog.com/u/PaulJackson)\
**Post date:** [June 29, 2021, 3:58pm UTC](https://community.stardog.com/t/graph-clause-causes-empty-result-set/3116/2 "2021-06-29T15:58:13Z")

</div>

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:

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

```

or even simply:

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

```

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

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

```

-Paul

---

<div class="post-metadata">

**Author:** ![PaulJackson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pauljackson/32/243_2.png) [@PaulJackson](https://community.stardog.com/u/PaulJackson)\
**Post date:** [June 29, 2021, 7:17pm UTC](https://community.stardog.com/t/graph-clause-causes-empty-result-set/3116/3 "2021-06-29T19:17:55Z")

</div>

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

> **[FROM vs FROM NAMED in SPARQL - Stardog](https://www.stardog.com/labs/blog/from-vs-from-named-in-sparql/)**
>
> FROM and FROM NAMED in SPARQL is a confusing topic and one of the main reasons why a query can surprisingly return zero results. The most experienced of us have been tricked by it at least once. This short post goes into a little bit of a detail of...

-Paul

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [July 13, 2021, 7:18pm UTC](https://community.stardog.com/t/graph-clause-causes-empty-result-set/3116/4 "2021-07-13T19:18:16Z")

</div>

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