0
votes

I need some help to write my update query.

DELETE {
      ?contactInfo vivo:freeTextValue5 ?o .
}
INSERT { 
      ?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
      ?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}

Can you please let me know what is wrong with this "update" query?

1
What makes you think anything is wrong with it? Are you getting an error when you execute it? If so: please edit your question to add the error message. If there's no error but you don't get what you want, please explain (again by editing your question) what you have tried to do, what you expected to happen, and what actually happened. Have a look at How to Ask for some tips on writing questions that have a high chance of getting a good answer. - Jeen Broekstra
I am wondering why "old_url"^^<http://www.w3.org/2001/XMLSchema#string> and not <http://example.com/old/url> ... - TallTed

1 Answers

0
votes

I'm guessing that your problem is that this update adds a new triple, but does not remove the old one.

The reason is that your DELETE clause contains an unbound variable: ?o. This is not allowed - or at least what happens is that patterns with unbound variables are simply ignored by the SPARQL engine. So your DELETE won't actually remove any triples. The variable ?o needs to be bound to a value in your WHERE clause.

One way to fix this is to just replace ?o with the specific value:

DELETE {
      ?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
INSERT { 
      ?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
      ?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}

More generally, you can use a VALUES clause to bind ?o to a value, like this:

DELETE {
      ?contactInfo vivo:freeTextValue5 ?o.
}
INSERT { 
      ?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
      VALUES ?o { "old_url"^^<http://www.w3.org/2001/XMLSchema#string> }
      ?contactInfo vivo:freeTextValue5 ?o.

}

This is perhaps the better approach as it makes it easier to extend your update to different values for ?o.