%META:TOPICPARENT{name="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection"}%
---+Virtuoso SPARQL 1.1. INSERT Usage Examples
%TOC%
---++What?
This guide contains Virtuoso SPARQL 1.1. INSERT Usage examples 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?
Using INSERTS provides flexible way of adding data to graphs.
---++How?
Here are some examples showcasing Virtuoso's support for this functionality:
---+++INSERT DATA Examples
---++++Adding One Triple Example
This example request describes 1 triple to be added to the named graph identified by the IRI <urn:sparql:tests:insert:data>
1 Assume the following Raw Data Representation in Turtle:
<#book1> <#price> 42 .
1 Load the sample data:
INSERT DATA
{
GRAPH
{
<#book1> <#price> 42
}
}
1 Query the graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/WFcxEN][View the SPARQL Query Definition via SPARQL Protocol URL]];
1 [[http://bit.ly/Xc45My][View the SPARQL Query Results via SPARQL Protocol URL]]
---+++INSERT (Informative) Examples
---++++Coping Triples Based on a Pattern Example
This example copies triples from one named graph to another named graph based on a pattern:
1 Assume the following Raw Data Representation in Turtle:
@prefix xsd: .
<#book1> "Fundamentals of Compiler Design" .
<#book1> "1977-01-01T00:00:00-02:00"^^xsd:dateTime .
<#book2> <#price> 42 .
<#book2> "David Copperfield" .
<#book2> "Edmund Wells" .
<#book2> "1948-01-01T00:00:00-02:00"^^xsd:dateTime .
<#book3> "SPARQL 1.1 Tutorial" .
1 Load the sample data into graph <urn:sparql:tests:insert:informative>;
PREFIX xsd:
INSERT INTO
{
<#book1> "Fundamentals of Compiler Design" .
<#book1> "1977-01-01T00:00:00-02:00"^^xsd:dateTime .
<#book2> <#price> 42 .
<#book2> "David Copperfield" .
<#book2> "Edmund Wells" .
<#book2> "1948-01-01T00:00:00-02:00"^^xsd:dateTime .
}
1 Assume another Raw Data Representation in Turtle:
<#book4> "SPARQL 1.0 Tutorial" .
1 Load the sample data into graph <urn:sparql:tests:insert:informative2>;
INSERT INTO
{
<#book4> "SPARQL 1.0 Tutorial" .
}
1 Copy triples from the <urn:sparql:tests:insert:informative2> named graph to the <urn:sparql:tests:insert:informative> named graph based on a pattern:
PREFIX xsd:
INSERT
{
GRAPH { ?book ?p ?v }
}
WHERE
{
GRAPH
{
?book ?date .
FILTER ( ?date > "1970-01-01T00:00:00-02:00"^^xsd:dateTime )
?book ?p ?v
}
}
1 Query the <urn:sparql:tests:insert:informative2> graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/VscJad][View the SPARQL Query Definition via SPARQL Protocol URL]];
1 [[http://bit.ly/U7dlqI][View the SPARQL Query Results via SPARQL Protocol URL]]
---++++Coping Triples Based on a Name and Mail Example
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:
1 Assume the following Raw Data Representation in Turtle:
_:a .
_:a "Alice" .
_:a .
_:b .
_:b "Bob" .
1 Load the sample data into graph <urn:sparql:tests:insert:informative3>;
INSERT INTO
{
_:a .
_:a "Alice" .
_:a .
_:b .
_:b "Bob" .
}
1 Assume in another named graph <urn:sparql:tests:insert:informative4> there are no triples inserted.
1 Copy triples of name and email from <urn:sparql:tests:insert:informative3> to <urn:sparql:tests:insert:informative4> :
INSERT
{
GRAPH
{
?person ?name .
?person ?email
}
}
WHERE
{
GRAPH
{
?person ?name .
OPTIONAL { ?person ?email }
}
}
1 Query the <urn:sparql:tests:insert:informative4> graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/WGBJ0v][View the SPARQL Query Definition via SPARQL Protocol URL]];
1 [[http://bit.ly/TkyT1t][View the SPARQL Query Results via SPARQL Protocol URL]]
---++++Copy Triples and Delete Physical Objects Example
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:
1 Assume the following Raw Data Representation in Turtle:
<#book1> "Fundamentals of Compiler Design" .
<#book1> "1996-01-01T00:00:00-02:00"^^xsd:dateTime .
<#book1> a .
<#book3> "SPARQL 1.1 Tutorial" .
1 Load the sample data into graph <urn:sparql:tests:insert:informative5>;
INSERT INTO
{
<#book1> "Fundamentals of Compiler Design" .
<#book1> "1996-01-01T00:00:00-02:00"^^xsd:dateTime .
<#book1> a .
<#book3> "SPARQL 1.1 Tutorial" .
}
1 Assume another Raw Data Representation in Turtle:
<#book4> "SPARQL 1.0 Tutorial" .
1 Load the sample data into graph <urn:sparql:tests:insert:informative6>;
INSERT INTO
{
<#book4> "SPARQL 1.0 Tutorial" .
}
1 Copy triples from <urn:sparql:tests:insert:informative5> to <urn:sparql:tests:insert:informative6>
PREFIX xsd:
INSERT
{
GRAPH { ?book ?p ?v }
}
WHERE
{
GRAPH
{
?book ?date .
FILTER ( ?date < "2000-01-01T00:00:00-02:00"^^xsd:dateTime )
?book ?p ?v
}
}
1 Delete triples about all the copied objects that are classified as Physical Objects:
PREFIX xsd:
WITH
DELETE
{
?book ?p ?v
}
WHERE
{
?book ?date ;
a .
FILTER ( ?date < "2000-01-01T00:00:00-02:00"^^xsd:dateTime )
?book ?p ?v .
}
1 Query the <urn:sparql:tests:insert:informative5> graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/Xca6Jg][View the SPARQL Query Definition via SPARQL Protocol URL]];
1 [[http://bit.ly/W6FCdX][View the SPARQL Query Results via SPARQL Protocol URL]]
1 Query the <urn:sparql:tests:insert:informative6> graph data:
SELECT *
FROM
WHERE
{
?s ?p ?o
}
1 [[http://bit.ly/XXIVCG][View the SPARQL Query Definition via SPARQL Protocol URL]];
1 [[http://bit.ly/12eJG15][View the SPARQL Query Results via SPARQL Protocol URL]]
---++Related
* [[http://www.w3.org/TR/2012/PR-sparql11-update-20121108/#insertData][SPARQL 1.1 INSERT DATA]]
* [[http://www.w3.org/TR/rdf-sparql-protocol/][SPARQL Protocol (HTTP based Query Service)]]
* [[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://bit.ly/Uo5hP6][Virtuoso SPARQL 1.1 INSERT Tutorial]]
* [[http://docs.openlinksw.com/virtuoso/rdfsparql.html][Virtuoso Documentation]]