问题
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