Skip to content

'Surprising' behaviour of @delete with variables #76

@gsvarovsky

Description

@gsvarovsky

See https://gitter.im/m-ld/community?at=6149e78a8065e87a8ef6167a

Violation of principle of least surprise.

You can always delete any old property value using a variable, like this:

{ "@delete": { "@id": "<id>", "<property>": "?value" } }

However there's a little subtlety to deletes with variables, which should probably be addressed with docs or maybe an improved semantic.

The subtlety is that the presence of a variable in the delete clause creates an implicit @where clause with the same content as the @delete, with the effective procedure:

  1. match graph triples against the (implicit) @where clause
  2. capture values for the variable ?value
  3. for each value found, substitute it into the @delete clause and delete those triples

So far this is the same behaviour as SPARQL DELETE WHERE.

The catch happens when you include a @insert clause as well, which you definitely want to do, if you are atomically updating a single-value property. Step 3 also applies to the insert; so if no value is matched, nothing gets inserted (even if the variable does not appear in the insert clause).

So, if you know there was definitely a value before (e.g. it's a mandatory property), you can just use a variable in the delete. But if you don't know that, then the only sane thing to do is to read the old value first, which is ungainly.

See also #31

Metadata

Metadata

Assignees

No one assigned

    Labels

    investigateExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions