0

I am trying to run this query in Amazon Neptune:

Delete{?s <http://mydomain#aresource> ?o.
          } 
WHERE {
    
    GRAPH ?g {
    
        ?s <http://mydomain#aresource> ?o.
        
    } 
} limit 1

But I'm getting this error:

"code": "MalformedQueryException",
"detailedMessage": "Malformed query: Encountered \" \"limit\" \"limit \"\" at line ..., column ....\nWas expecting one of:\n    <EOF> \n    \";\" ...\n    "

When I remove the limit, the query works. Does this mean that Neptune delete does not support the limit or am I doing something wrong?

Bahar
  • 770
  • 5
  • 18

1 Answers1

3

I am not an expert at interpreting the SPARQL grammar, but I don't believe LIMIT on a DELETE WHERE clause is valid. However, the following query will achieve what I believe you are looking for...

DELETE {
    ?s <http://mydomain#aresource> ?o.
} 
WHERE {    
    SELECT ?s ?o WHERE {
        GRAPH ?g {
            ?s <http://mydomain#aresource> ?o.        
        } 
    } LIMIT 1
} 

To prove this, I ran the following sequence of commands in Neptune.

First,

INSERT DATA {
<http://test/a> <http://mydomain#aresource> <http://test/b> .
<http://test/c> <http://mydomain#aresource> <http://test/d> .
<http://test/e> <http://mydomain#aresource> <http://test/f> .
}

Then the DELETE WHERE query above. Finally,

SELECT ?s ?o WHERE {?s <http://mydomain#aresource> ?o.}

and received the output

{
  "head": {
    "vars": [
      "s",
      "o"
    ]
  },
  "results": {
    "bindings": [
      {
        "s": {
          "type": "uri",
          "value": "http://test/c"
        },
        "o": {
          "type": "uri",
          "value": "http://test/d"
        }
      },
      {
        "s": {
          "type": "uri",
          "value": "http://test/e"
        },
        "o": {
          "type": "uri",
          "value": "http://test/f"
        }
      }
    ]
  }
}