Can anyone point me to a valid UPDATE statement in SPARQL in any documentation (be it W3C, virtuoso, semantic web page, or your own custom code, etc?
It has
In SPARQL updates are represented as a DELETE followed by an INSERT:
http://www.w3.org/TR/2010/WD-sparql11-update-20100126/#t413
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
WITH <http://example/addresses>
DELETE { ?person foaf:firstName 'Bill' }
INSERT { ?person foaf:firstName 'William' }
WHERE
{ ?person a foaf:Person .
?person foaf:firstName 'Bill'
}
Hallelujah thank God.
After 3 days hitting my head on the wall I believe I have the solution, which is like a work around. First you make the DELETE
statement, then you use the semicolon to specify the triples you want to insert. Its still two operations, but at least they are controlled by the query server, i. e. you do not have to perform two separate requests, one for DELETE
other for UPDATE
(very dangerous).
Here is my working code, now (apparrently) fixed:
WITH GRAPH <http://127.0.0.1:3000/dendro_graph>
DELETE
{
:teste dc:creator ?o0 .
:teste dc:title ?o1 .
}
WHERE
{
:teste dc:creator ?o0 .
:teste dc:title ?o1 .
};
<------NOTE THE SEMICOLON at the end of the first part
INSERT DATA
{
:teste dc:creator "criador%20do%20teste" .
:teste dc:creator "second%20criador%20do%20teste" .
:teste dc:creator "third%20criador%20do%20teste" .
:teste dc:creator "fourth%20criador%20do%20teste" .
:teste dc:title "t1" .
:teste dc:title "t3" .
:teste dc:title "second%20title" .
}
It's still not entirely clear to me what you're trying to achieve and why the example update that you give is not doing what you want, but if the aim is to have an update that replaces triples for a given subject, you could do something like this:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix ex: <http://example.org/>
DELETE {?s ?p ?o}
INSERT {?s ex:title "foo" ;
ex:description "bar" ;
rdf:type ex:FooBar .
}
WHERE { ?s ?p ?o .
FILTER (?s = ex:subject1)
}
The above operation will delete all existing triples with ex:subject1
as the subject, and insert a new title, description, and type.
Or if you don't like filters, you can also formulate the above like this:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix ex: <http://example.org/>
DELETE {ex:subject1 ?p ?o}
INSERT {ex:subject1 ex:title "foo" ;
ex:description "bar" ;
rdf:type ex:FooBar .
}
WHERE {
ex:subject1 ?p ?o .
}
If you only want to delete specific properties for a given subject (rather than all triples with that subject), you can modify the operation like so:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix ex: <http://example.org/>
DELETE {ex:subject1 ex:title ?t ;
ex:description ?d ;
rdf:type ?c .
}
INSERT {ex:subject1 ex:title "foo" ;
ex:description "bar" ;
rdf:type ex:FooBar .
}
WHERE {
ex:subject1 ex:title ?t ;
ex:description ?d ;
rdf:type ?c .
}
sparql insert is not possible .the sparql processing for already mapping & dump rdf files . Its a only query processing for linked data or graph data.not database for like mysql,sql,etc...
the rdf file for subject object predicate format.
the sparql query for select * where{?s ?p ?o. }get result