Search code examples
sqlsparqlsql-likesemantic-web

Selecting strings with LIKE operator in SPARQL


In ANSI SQL, you can write something like:

SELECT * FROM DBTable WHERE Description LIKE 'MEET'

or also:

SELECT * FROM DBTable WHERE Description LIKE '%MEET%'

What I would like help with is writing the SPARQL equivalent of the above please.


Solution

  • Use a regex filter. You can find a short tutorial here

    Here's what it looks like:

    PREFIX ns: <http://example.com/namespace>
    
    SELECT ?x
    WHERE
    { ?x ns:SomePredicate ?y .
      FILTER regex(?y, "YOUR_REGEX", "i") }
    

    YOUR_REGEX must be an expression of the XQuery regular expression language

    i is an optional flag. It means that the match is case insensitive.