Here are some examples showcasing Virtuoso's support for this functionality:
This example request describes 1 triple to be added to the named graph identified by the IRI <urn:sparql:tests:insert:data>
<#book1> <#price> 42 .
INSERT DATA { GRAPH <urn:sparql:tests:insert:data> { <#book1> <#price> 42 } }
SELECT * FROM <urn:sparql:tests:insert:data> WHERE { ?s ?p ?o }
This example copies triples from one named graph to another named graph based on a pattern:
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" . <#book1> <http://purl.org/dc/elements/1.1/date> "1977-01-01T00:00:00-02:00"^^xsd:dateTime . <#book2> <#price> 42 . <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" . <#book2> <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . <#book2> <http://purl.org/dc/elements/1.1/date> "1948-01-01T00:00:00-02:00"^^xsd:dateTime . <#book3> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.1 Tutorial" .
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> INSERT INTO <urn:sparql:tests:insert:informative> { <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" . <#book1> <http://purl.org/dc/elements/1.1/date> "1977-01-01T00:00:00-02:00"^^xsd:dateTime . <#book2> <#price> 42 . <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" . <#book2> <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . <#book2> <http://purl.org/dc/elements/1.1/date> "1948-01-01T00:00:00-02:00"^^xsd:dateTime . }
<#book4> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.0 Tutorial" .
INSERT INTO <urn:sparql:tests:insert:informative2> { <#book4> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.0 Tutorial" . }
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> INSERT { GRAPH <urn:sparql:tests:insert:informative2> { ?book ?p ?v } } WHERE { GRAPH <urn:sparql:tests:insert:informative> { ?book <http://purl.org/dc/elements/1.1/date> ?date . FILTER ( ?date > "1970-01-01T00:00:00-02:00"^^xsd:dateTime ) ?book ?p ?v } }
SELECT * FROM <urn:sparql:tests:insert:informative2> WHERE { ?s ?p ?o }
This example copies triples of name and email from one named graph to another. Some individuals may not have an address, but the name is copied regardless:
_:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . _:a <http://xmlns.com/foaf/0.1/name> "Alice" . _:a <http://xmlns.com/foaf/0.1/mbox> <mailto:alice@example.com> . _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . _:b <http://xmlns.com/foaf/0.1/name> "Bob" .
INSERT INTO <urn:sparql:tests:insert:informative3> { _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . _:a <http://xmlns.com/foaf/0.1/name> "Alice" . _:a <http://xmlns.com/foaf/0.1/mbox> <mailto:alice@example.com> . _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . _:b <http://xmlns.com/foaf/0.1/name> "Bob" . }
INSERT { GRAPH <urn:sparql:tests:insert:informative4> { ?person <http://xmlns.com/foaf/0.1/name> ?name . ?person <http://xmlns.com/foaf/0.1/mbox> ?email } } WHERE { GRAPH <urn:sparql:tests:insert:informative3> { ?person <http://xmlns.com/foaf/0.1/name> ?name . OPTIONAL { ?person <http://xmlns.com/foaf/0.1/mbox> ?email } } }
SELECT * FROM <urn:sparql:tests:insert:informative4> WHERE { ?s ?p ?o }
This example request first copies triples from one named graph to another named graph based on a pattern; triples about all the copied objects that are classified as Physical Objects are then deleted. This demonstrates two operations in a single request, both of which share common PREFIX definitions:
<#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" . <#book1> <http://purl.org/dc/elements/1.1/date> "1996-01-01T00:00:00-02:00"^^xsd:dateTime . <#book1> a <http://purl.org/dc/dcmitype/PhysicalObject> . <#book3> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.1 Tutorial" .
INSERT INTO <urn:sparql:tests:insert:informative5> { <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" . <#book1> <http://purl.org/dc/elements/1.1/date> "1996-01-01T00:00:00-02:00"^^xsd:dateTime . <#book1> a <http://purl.org/dc/dcmitype/PhysicalObject> . <#book3> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.1 Tutorial" . }
<#book4> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.0 Tutorial" .
INSERT INTO <urn:sparql:tests:insert:informative6> { <#book4> <http://purl.org/dc/elements/1.1/title> "SPARQL 1.0 Tutorial" . }
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> INSERT { GRAPH <urn:sparql:tests:insert:informative6> { ?book ?p ?v } } WHERE { GRAPH <urn:sparql:tests:insert:informative5> { ?book <http://purl.org/dc/elements/1.1/date> ?date . FILTER ( ?date < "2000-01-01T00:00:00-02:00"^^xsd:dateTime ) ?book ?p ?v } }
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> WITH <urn:sparql:tests:insert:informative5> DELETE { ?book ?p ?v } WHERE { ?book <http://purl.org/dc/elements/1.1/date> ?date ; a <http://purl.org/dc/dcmitype/PhysicalObject> . FILTER ( ?date < "2000-01-01T00:00:00-02:00"^^xsd:dateTime ) ?book ?p ?v . }
SELECT * FROM <urn:sparql:tests:insert:informative5> WHERE { ?s ?p ?o }
SELECT * FROM <urn:sparql:tests:insert:informative6> WHERE { ?s ?p ?o }