Multiple SPARQL "INSERT WHERE" queries in a single request

rdf, sparql

Solution

Yes, this is possible. In fact, your example is almost completely fine, just lose the brackets around each insert:

PREFIX Sensor: <http://example.com/Equipment.owl#> 
INSERT { 
    ?subject1 Sensor:test2 'newValue1' . 
}
WHERE {
    ?subject1 Sensor:test1  'testValue1' . 
};
INSERT { 
   ?subject2 Sensor:test2 'newValue2' . 
}
WHERE {
   ?subject2 Sensor:test1  'testValue2' . 
}

is a valid SPARQL update sequence.

Problem

My question is similar to what was asked on this thread Is it possible to combine those 2 SPARQL INSERT into one? I want to have multiple INSERT WHERE statements in a query, but for different subjects. I will like to test a particular value ("testValueN") and if present would like to insert a new triple for that subject. An example of it would be, ``` PREFIX Sensor: <http://example.com/Equipment.owl#> { INSERT { ?subject1 Sensor:test2 'newValue1' . } WHERE { ?subject1 Sensor:test1 'testValue1' . } }; { INSERT { ?subject2 Sensor:test2 'newValue2' . } WHERE { ?subject2 Sensor:test1 'testValue2' . } }; ``` I know the above query is wrong. I would like to know if something similar is possible in SPARQL.

Original source