%META:TOPICPARENT{name="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection"}%
---+Virtuoso SPARQL 1.1. Update Examples
%TOC%
---++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 ( [[http://www.w3.org/TR/2012/PR-sparql11-update-20121108/#graphUpdate][See more from the specification]] ):
* [[VirtTipsAndTricksSPARQL11Insert][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.
* [[VirtTipsAndTricksSPARQL11Delete][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.
* [[VirtTipsAndTricksSPARQL11Load][LOAD]] -- reads the contents of a document representing a graph into a graph in the Graph Store.
* [[VirtTipsAndTricksSPARQL11Clear][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> :
1 Assume the following Raw Data Representation in Turtle:
<#book1> "Fundamentals of Compiler Desing" .
1 Load the sample data:
INSERT DATA
{
GRAPH
{
<#book1> "Fundamentals of Compiler Design" .
}
}
1 Delete the triple from the graph:
DELETE DATA
{
GRAPH
{
<#book1> "Fundamentals of Compiler Design"
}
}
1 Insert a new triple to the graph:
INSERT DATA
{
GRAPH
{
<#book2> "Fundamentals of Compiler Design"
}
}
1 Query the graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/Ua3MHI][View the SPARQL Query Definition via SPARQL Protocol URL]]
1 [[http://bit.ly/UKCANo][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":
1 Assume the following Raw Data Representation in Turtle:
<#president25> "Bill" .
<#president25> "McKinley" .
<#president27> "Bill" .
<#president27> "Taft" .
<#president42> "Bill" .
<#president42> "Clinton" .
1 Load the sample data:
INSERT DATA
{
GRAPH
{
<#president25> "Bill" .
<#president25> "McKinley" .
<#president27> "Bill" .
<#president27> "Taft" .
<#president42> "Bill" .
<#president42> "Clinton" .
}
}
1 Rename all people with the given name "Bill" to "William":
WITH
DELETE { ?person 'Bill' }
INSERT { ?person 'William' }
WHERE
{
?person 'Bill'
}
1 Query the graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/WZVZbV][View the SPARQL Query Definition via SPARQL Protocol URL]]
1 [[http://bit.ly/11uJAgW][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> .
1 Assume the following Raw Data Representation in Turtle:
.
.
.
.
.
1 Load the sample data:
INSERT DATA
{
GRAPH
{
.
.
.
.
.
}
}
1 Assume the following Raw Data Representation in Turtle:
.
.
.
.
.
1 Load the sample data:
INSERT DATA
{
GRAPH
{
.
.
.
.
.
}
}
1 Replace schema:WebPage objects with foaf:home objects values:
PREFIX schema:
PREFIX foaf:
MODIFY
DELETE
{
schema:WebPage ?s .
}
INSERT
{
schema:WebPage ?ns .
}
WHERE
{
GRAPH
{
schema:WebPage ?s .
}
GRAPH
{
?s foaf:homepage ?ns .
}
}
1 Query the graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o .
FILTER (?s = ) .
}
1 [[http://bit.ly/1EuDfaP][View the SPARQL Query Definition via SPARQL Protocol URL]]
1 [[http://bit.ly/1srjQyX][View the SPARQL Query Results via SPARQL Protocol URL]]
---++Related
* [[http://www.w3.org/TR/2012/PR-sparql11-update-20121108/#graphUpdate][SPARQL 1.1 Update]]
* [[http://www.w3.org/TR/2012/PR-sparql11-update-20121108/#deleteInsert][SPARQL 1.1. DELETE/INSERT + WITH clause]]
* [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]]
* [[VirtTipsAndTricksSPARQL11FeaturesExamplesCollection][Virtuoso SPARQL 1.1 Usage Examples Collection]]
* [[http://virtuoso.openlinksw.com/tutorials/sparql/SPARQL_Tutorials_Part_9/SPARQL_Tutorials_Part_9.html][Virtuoso SPARQL 1.1 Syntax Tutorial]]
* [[http://docs.openlinksw.com/virtuoso/rdfsparql.html][Virtuoso Documentation]]