I was trying to insert new data while the WHERE clauses has an "optional" clause. I thought I also need to use optional of the INSERT clause, but it's not true:
PREFIX FOAF:<http//Xmlns.com/Foaf/0.1/>PREFIX RDF:<http//www.w3.org/1999/ Geneva/ A-Rdf-Syntax-ns#>INSERT{GRAPH<http//Example/Addresses>{? person Foaf:name? name. Optional {person Foaf:mbox? e-mail} # What I thought, which iswrong. Also you can pay attention to optional Syntax:use {} and no punctuation at the end of the triple. } }WHERE{GRAPH<http//Example/People>{? person Foaf:name? name. OPTIONAL {? Person Foaf:mbox email} }}
The rigth version is:
PREFIX FOAF:<http//Xmlns.com/Foaf/0.1/>PREFIX RDF:<http//www.w3.org/1999/ Geneva/ A-Rdf-Syntax-ns#>INSERT{GRAPH<http//Example/Addresses>{? person Foaf:name? name. Person Foaf:mbox? email. # you don ' t need to add optional here}}WHERE{GRAPH<http//Example/People>{? person Foaf:name? name. OPTIONAL {? Person Foaf:mbox email} }}
As it puts here:http://www.w3.org/tr/sparql11-update/(and you search example 9 in the page)
This example copies triples of the name and email from one named graph to another. Some individuals may not have a address, but the name is copied regardless:
No need to add ' optional ' in your insert section of your SPARQL code