I try to use the SPARQL Update query such that it will delete triples if its in the graph and afterwards insert new triples even if no delete happened.
I have this query as example in the Virtuoso SPARQL endpoint after creating the graph http://example.de/:
WITH <http://example.de/>
DELETE {
<http://example.de/Rheinmetall+AG>
<http://dbpedia.org/property/locationStreet>
?0 .
}
INSERT {
<http://example.de/Rheinmetall+AG>
<http://dbpedia.org/property/locationStreet>
<http://dbpedia.org/resource/Rheinmetall+Platz+1> .
}
WHERE
{ OPTIONAL
{ <http://example.de/Rheinmetall+AG>
<http://dbpedia.org/property/locationStreet>
?0
}
}
It doesn't insert any triples:
Modify <http://example.de/>, delete 0 (or less) and insert 0 (or less) triples -- done
If I leave the WHERE clause empty it will insert one triple. And afterwards the original query will also delete and insert one triple.
But I also want it to work if the triple is not in the graph yet. Is it possible to overcome that problem in an update query or do I have to call delete and insert separately?
Thanks for any help!
INSERT DATAfor the triple that you always want to add. And then;and thenDELETE ... WHEREstatement - UninformedUserOPTIONALdidn't work because it's basically a left-join on an empty table - UninformedUserGRAPH <nosuchurui> { pattern }. See answer. The WHERE pattern of { OPTIONAL {...} } is a left-join on the unit table which is why it works in the default graph case. - AndySDELETEall matching triples if present, and thenINSERTone triple. Doing theINSERTfirst would mean that the triple in theINSERTquery would then immediately be caught in theDELETEquery. - TallTedWITHclause is always present, in all described tests. The change they made is in theWHEREclause. - TallTed