%META:TOPICPARENT{name="VirtTipsAndTricksGuide"}% ---++How Can I execute SPARQL queries containing '$' character using ISQL? Assuming a SPARQL query should filter on the length of labels: SELECT ?label FROM WHERE { ?s ?p ?label FILTER(regex(str(?label), "^.{1,256}$") ) } [[http://lod.openlinksw.com/sparql?default-graph-uri=&query=SELECT+%3Flabel%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+%3Fp+%3Flabel%0D%0A++++FILTER%28regex%28str%28%3Flabel%29%2C+%22%5E.%7B1%2C256%7D%24%22%29+%29%0D%0A++%7D+&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=15000&debug=on][View the results]] of the query execution on the [[http://lod.openlinksw.com][LOD]] instance. ISQL uses '$' character as a prefix for macro names of its preprocessor. When '$' character is used in SPARQL query to be executed in ISQL, the character should be replaced with '$$' notation or an escape char + numeric code: SQL> SPARQL SELECT ?label FROM WHERE { ?s ?p ?label FILTER(REGEX(str(?label), "^.{1,256}$$") ) } [[http://lod.openlinksw.com/sparql?default-graph-uri=&query=SELECT+%3Flabel%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+%3Fp+%3Flabel%0D%0A++++FILTER%28REGEX%28str%28%3Flabel%29%2C+%22%5E.%7B1%2C256%7D%24%24%22%29+%29%0D%0A++%7D+&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=15000&debug=on][View the results]] of the query execution on the [[http://lod.openlinksw.com][LOD]] instance. Note also that the FILTER written in this way, finds ?label-s with length less than 256. To achieve fast results, REGEX should be replaced with the bif:length function: SQL> SPARQL SELECT ?label FROM WHERE { ?s ?p ?label FILTER (bif:length(str(?label))<= 256) } In this way the SPARQL query execution can work much faster if the interoperability is not required and ?label-s are numerous. [[http://lod.openlinksw.com/sparql?default-graph-uri=&query=SELECT+%3Flabel%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+%3Fp+%3Flabel%0D%0A++++FILTER+%28bif%3Alength%28str%28%3Flabel%29%29%3C%3D+256%29%0D%0A++%7D+&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=15000&debug=on][View the results]] of the query execution on the [[http://lod.openlinksw.com][LOD]] instance. ---+++Related * [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]] * [[http://docs.openlinksw.com/virtuoso/rdfandsparql.html][RDF Data Access and Data Management]]