Cheryl
Cheryl

Reputation: 245

SPARQL insert query not inserting

When I run this SPARQL update:

INSERT {
  GRAPH <n4> {
    ?s foaf:firstName ?o
  }
}
WHERE {
  GRAPH <n1> {
    ?s foaf:familyName ?o .
    ?o foaf:familyName ?x
  }
}

Although it is syntactically fine, I get no results. Is it because ?s from the INSERT clause can not be bound to ?s and ?o simultaneously?

Upvotes: 1

Views: 1047

Answers (2)

Cheryl
Cheryl

Reputation: 245

I used 0.2.7 edition of Jena Fuseki. I think the problem was that I had to create explicitly the graph and after that to run the INSERT Update. This works for one graph although, if you want to evaluate the groupgraphpattern to a larger dataset (e.g. n1, n2, n3) it gives you no results.

Upvotes: 1

Joshua Taylor
Joshua Taylor

Reputation: 85853

Your query is syntactically fine for SPARQL, but the patterns that it would match probably, in most cases, aren't legal RDF. In particular, it's unlikely that this pattern:

?s foaf:familyName ?o .
?o foaf:familyName ?x

will ever match your data. The value of ?o is very likely to be a string, which is an RDF literal, and literals cannot be the subjects of triples in RDF, so it's very unlikely that ?o foaf:familyName ?x can ever match. Since this means that no triples will match the WHERE part of the query, there's nothing to insert. I'd suggest that you first run

SELECT ?s ?o WHERE {
  GRAPH <n1> {
    ?s foaf:familyName ?o .
    ?o foaf:familyName ?x
  }
}

to see what values of ?s and ?o would available for the INSERT. I expect that you won't see any results, and that's why you're not inserting any triples into n4.

As to the particular question that you asked,

Is it because ?s from the INSERT clause can not be bound to ?s and ?o simultaneously?

there's no issue about simultaneous bindings. The WHERE part of the query produces a (possibly empty) set of results, each of which binds ?s, ?o, and ?x. Then, for each solution, the values of ?s and ?o are used to construct the triple value-of-s foaf:firstName value-of-o and all of those triples are inserted into n4. Nothing is getting inserted into n4 because the set of results is empty (for the reasons described above).

Upvotes: 3

Related Questions