Search code examples
sparqlvirtuosonamed-graphs

Escaping < in graph name SPARQL


I accidentally created a graph with a name that begins with < and ends with >.

If I try to clear the graph from the Virtuoso server by --

clear graph <graph_name>

-- or --

clear graph <<graph_name>>

-- or --

clear graph <\<graph_name\>>

-- it does not work. They all give similar errors:

*** Error 37000: [Virtuoso Driver][Virtuoso Server]SQ074: Line 1: SPARQL compiler, line 1: syntax error at '<' before '<graph_name>


Solution

  • < and > are illegal in URIs so the parser is going to get upset if used directly.

    CLEAR can be thought of as a short form of DELETE so you can try:

    DELETE { GRAPH ?g { ?s ?p ?o } }
    WHERE { GRAPH ?g { ?s ?p ?o } 
            FILTER (str(?g) = '<graph_name>')
          }