<docbook><section><title>VirtTipsAndTricksGuideSpChar</title><bridgehead class="http://www.w3.org/1999/xhtml:h2">How Can I execute SPARQL queries containing &#39;$&#39; character using ISQL?</bridgehead>
<para>Assuming a SPARQL query should filter on the length of labels:</para>
<programlisting>SELECT ?label
FROM &lt;http://mygraph.com&gt;
WHERE 
  { 
    ?s ?p ?label
    FILTER(regex(str(?label), &quot;^.{1,256}$&quot;) )
  } 
</programlisting><para> <ulink url="http://lod.openlinksw.com/sparql?default-graph-uri=&amp;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+&amp;should-sponge=&amp;format=text%2Fhtml&amp;CXML_redir_for_subjs=121&amp;CXML_redir_for_hrefs=&amp;timeout=15000&amp;debug=on">View the results</ulink> of the query execution on the <ulink url="http://lod.openlinksw.com">LOD</ulink> instance.</para>
<para>ISQL uses &#39;$&#39; character as a prefix for macro names of its preprocessor.
 When &#39;<emphasis>$</emphasis>&#39; character is used in SPARQL query to be executed in ISQL, the character should be replaced with &#39;<emphasis>$$</emphasis>&#39; notation or an escape char + numeric code:</para>
<programlisting>SQL&gt; SPARQL 
SELECT ?label
FROM &lt;http://mygraph.com&gt;
WHERE 
  { 
    ?s ?p ?label
    FILTER(REGEX(str(?label), &quot;^.{1,256}$$&quot;) )
  } 
</programlisting><para> <ulink url="http://lod.openlinksw.com/sparql?default-graph-uri=&amp;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+&amp;should-sponge=&amp;format=text%2Fhtml&amp;CXML_redir_for_subjs=121&amp;CXML_redir_for_hrefs=&amp;timeout=15000&amp;debug=on">View the results</ulink> of the query execution on the <ulink url="http://lod.openlinksw.com">LOD</ulink> instance.</para>
<para> Note also that the FILTER written in this way, finds <emphasis>?label-s</emphasis> with length less than 256.</para>
<para>To achieve fast results, <emphasis>REGEX</emphasis> should be replaced with the <emphasis>bif:length</emphasis> function:</para>
<programlisting>SQL&gt; SPARQL 
SELECT ?label
FROM &lt;http://mygraph.com&gt;
WHERE 
  { 
    ?s ?p ?label
    FILTER (bif:length(str(?label))&lt;= 256)
  } 
</programlisting><para> In this way the SPARQL query execution can work much faster if the interoperability is not required and <emphasis>?label-s</emphasis> are numerous.</para>
<para><ulink url="http://lod.openlinksw.com/sparql?default-graph-uri=&amp;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+&amp;should-sponge=&amp;format=text%2Fhtml&amp;CXML_redir_for_subjs=121&amp;CXML_redir_for_hrefs=&amp;timeout=15000&amp;debug=on">View the results</ulink> of the query execution on the <ulink url="http://lod.openlinksw.com">LOD</ulink> instance.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Related</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="VirtTipsAndTricksGuide">Virtuoso Tips and Tricks Collection</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/virtuoso/rdfandsparql.html">RDF Data Access and Data Management</ulink> </listitem>
</itemizedlist></section></docbook>