Search code examples
curlpostmansparqlrdfamazon-neptune

Clear data in AWS Neptune


I am trying to run simple CLEAR and DELETE SPARQL queries and keep getting back:

    Malformed query: Encountered \" \"clear\" \"CLEAR \"\" at line
    1, column 1.\n Was expecting one of:\n \"base\" ...\n \"prefix\" 
...\n \"select\" ...\n \"construct\" ...\n \ "describe\" ...\n \"ask\" ...\n

Are the CLEAR and DELETE queries not supported? or does Neptune have another way of clearing the graph in the instance.

Thanks


Solution

  • Word of Caution: The answer contains examples to DELETE all your data, so be extra careful when you execute these queries in your database.

    Neptune does support CLEAR and DELETE. CLEAR and DELETE are UPDATE operations, so you can do them in two ways:

    1) Use "update=" in the request params

    curl http://endpoint:8182/sparql -d "update=DELETE DATA { <http://x> <http://y> <http://z> }” 
    
    OR
    
    curl http://localhost:8182/sparql -d "update=DELETE WHERE { ... }” 
    
    You can use a similar one for CLEAR.
    

    2) Use Content-Type Header (application/sparql-update) and use the query directly in request params.

    curl http://endpoint:8182/sparql -H "Content-Type: application/sparql-update" -d "DELETE DATA { <http://x> <http://y> <http://z> }” 
    
    

    It looks like you tried a mix of both, and possibly got the combination incorrect. Neptune is fully SPARQL 1.1 compliant, so if you see something to not be working, do let us know. In almost all cases, the request would not have adhered to the SPARQL HTTP spec.