SPARQL INSERT/DELETE

强颜欢笑 提交于 2019-12-25 03:43:01

问题


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:


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.



来源:https://stackoverflow.com/questions/53843724/sparql-insert-delete

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!