VirtTipsAndTricksSPARQL11UpdateVirtuoso SPARQL 1.1. Update ExamplesVirtuoso SPARQL 1.1. Update Examples What? This guide contains Virtuoso SPARQL 1.1. Update Usage example queries which you can run against any SPARQL endpoint that supports SPARQL 1.1 and the ability to allow a verified user perform INSERT operations.Why? Change existing graphs in the Quad Store.How? SPARQL 1.1 Update provides these graph update operations ( See more from the specification ): INSERT DATA -- adds some triples, given inline in the request, into a graph. This SHOULD create the destination graph if it does not exist. If the graph does not exist and it can not be created for any reason, then a failure MUST be returned. DELETE DATA -- removes some triples, given inline in the request, if the respective graph contains those. The fundamental pattern-based actions for graph updates are INSERT and DELETE. These actions consist of groups of triples to be deleted and groups of triples to be added based on query patterns. The difference between INSERT / DELETE and INSERT DATA / DELETE DATA is that INSERT DATA and DELETE DATA do not substitute bindings into a template from a pattern. LOAD -- reads the contents of a document representing a graph into a graph in the Graph Store. CLEAR -- removes all the triples in (one or more) graphs. Here are some examples showcasing Virtuoso's support for this functionality: Delete and Add a Triple to a Graph Example This example demonstrates two operations -- delete a triple and add a triple in the named graph identified by the IRI <urn:sparql:tests:update> : Assume the following Raw Data Representation in Turtle: <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Desing" . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:update> { <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" . } } Delete the triple from the graph: DELETE DATA { GRAPH <urn:sparql:tests:update> { <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" } } Insert a new triple to the graph: INSERT DATA { GRAPH <urn:sparql:tests:update> { <#book2> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" } } Query the graph data: SELECT * FROM <urn:sparql:tests:update> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL View the SPARQL Query Results via SPARQL Protocol URL DELETE/Insert WITH Clause Usage Example This example demonstrates how to rename all people with the given name "Bill" to "William": Assume the following Raw Data Representation in Turtle: <#president25> <http://xmlns.com/foaf/0.1/givenName> "Bill" . <#president25> <http://xmlns.com/foaf/0.1/foaf:familyName> "McKinley" . <#president27> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president27> <http://xmlns.com/foaf/0.1/foaf:familyName> "Taft" . <#president42> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president42> <http://xmlns.com/foaf/0.1/foaf:familyName> "Clinton" . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:update:insert:delete:with> { <#president25> <http://xmlns.com/foaf/0.1/givenName> "Bill" . <#president25> <http://xmlns.com/foaf/0.1/foaf:familyName> "McKinley" . <#president27> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president27> <http://xmlns.com/foaf/0.1/foaf:familyName> "Taft" . <#president42> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president42> <http://xmlns.com/foaf/0.1/foaf:familyName> "Clinton" . } } Rename all people with the given name "Bill" to "William": WITH <urn:sparql:tests:update:insert:delete:with> DELETE { ?person <http://xmlns.com/foaf/0.1/givenName> 'Bill' } INSERT { ?person <http://xmlns.com/foaf/0.1/givenName> 'William' } WHERE { ?person <http://xmlns.com/foaf/0.1/givenName> 'Bill' } Query the graph data: SELECT * FROM <urn:sparql:tests:update:insert:delete:with> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL View the SPARQL Query Results via SPARQL Protocol URL DELETE/Insert WITH MODIFY Usage Example This example demonstrates use of MODIFY to alter the objects of a schema:WebPage relation using objects of a foaf:homePage relation. In this example, we have a constant relation subject identified the HTTP URI <http://example.com/product/Sample1#this> . Assume the following Raw Data Representation in Turtle: <http://example.com/product/Sample1#this> <http://schema.org/WebPage> <http://sample1.com/index1> . <http://example.com/product/Sample2#this> <http://schema.org/WebPage> <http://sample2.com/index2> . <http://example.com/product/Sample3#this> <http://schema.org/WebPage> <http://sample3.com/index3> . <http://example.com/product/Sample4#this> <http://schema.org/WebPage> <http://sample4.com/index4> . <http://example.com/product/Sample5#this> <http://schema.org/WebPage> <http://sample5.com/index5> . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:update:insert:delete:modify:graph1> { <http://example.com/product/Sample1#this> <http://schema.org/WebPage> <http://sample1.com/index1> . <http://example.com/product/Sample2#this> <http://schema.org/WebPage> <http://sample2.com/index2> . <http://example.com/product/Sample3#this> <http://schema.org/WebPage> <http://sample3.com/index3> . <http://example.com/product/Sample4#this> <http://schema.org/WebPage> <http://sample4.com/index4> . <http://example.com/product/Sample5#this> <http://schema.org/WebPage> <http://sample5.com/index5> . } } Assume the following Raw Data Representation in Turtle: <http://sample1.com/index1> <http://xmlns.com/foaf/0.1/homepage> <http://sample1.com/> . <http://sample2.com/index2> <http://xmlns.com/foaf/0.1/homepage> <http://sample2.com/> . <http://sample3.com/index3> <http://xmlns.com/foaf/0.1/homepage> <http://sample3.com/> . <http://sample4.com/index4> <http://xmlns.com/foaf/0.1/homepage> <http://sample4.com/> . <http://sample5.com/index5> <http://xmlns.com/foaf/0.1/homepage> <http://sample5.com/> . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:update:insert:delete:modify:graph2> { <http://sample1.com/index1> <http://xmlns.com/foaf/0.1/homepage> <http://sample1.com/> . <http://sample2.com/index2> <http://xmlns.com/foaf/0.1/homepage> <http://sample2.com/> . <http://sample3.com/index3> <http://xmlns.com/foaf/0.1/homepage> <http://sample3.com/> . <http://sample4.com/index4> <http://xmlns.com/foaf/0.1/homepage> <http://sample4.com/> . <http://sample5.com/index5> <http://xmlns.com/foaf/0.1/homepage> <http://sample5.com/> . } } Replace schema:WebPage objects with foaf:home objects values: PREFIX schema: <http://schema.org/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> MODIFY <urn:sparql:tests:update:insert:delete:modify:graph1> DELETE { <http://example.com/product/Sample1#this> schema:WebPage ?s . } INSERT { <http://example.com/product/Sample1#this> schema:WebPage ?ns . } WHERE { GRAPH <urn:sparql:tests:update:insert:delete:modify:graph1> { <http://example.com/product/Sample1#this> schema:WebPage ?s . } GRAPH <urn:sparql:tests:update:insert:delete:modify:graph2> { ?s foaf:homepage ?ns . } } Query the graph data: SELECT * FROM <urn:sparql:tests:update:insert:delete:modify:graph1> WHERE { ?s ?p ?o . FILTER (?s = <http://example.com/product/Sample1#this>) . } View the SPARQL Query Definition via SPARQL Protocol URL View the SPARQL Query Results via SPARQL Protocol URL Related SPARQL 1.1 Update SPARQL 1.1. DELETE/INSERT + WITH clause Virtuoso Tips and Tricks Collection Virtuoso SPARQL 1.1 Usage Examples Collection Virtuoso SPARQL 1.1 Syntax Tutorial Virtuoso Documentation