LIKE

All functions > COMPARISON > LIKE

Returns TRUE if a string matches a specified pattern with wildcards.

Syntax

string LIKE pattern

Function form

Returns: TRUE if the string matches, FALSE if not, NULL if an input is NULL

LIKE(expr1: VARCHAR, expr2: VARCHAR, [escape: VARCHAR]) → BOOLEAN
sql
ParameterTypeRequiredDescription
expr1VARCHARYesString to match
expr2VARCHARYesPattern (% and _ wildcards)
escapeVARCHARNoEscape character for wildcards

Notes

  • Wildcard pattern matching
  • % matches zero or more characters
  • _ matches exactly one character
  • Case-sensitive matching
  • NULL inputs return NULL
  • An escape character can treat % and _ literally (default escape is backslash in the lowering template)

Examples

Basic pattern matching

FeatureQL
RETURN
    -- Starts with 'h'
    f1 := 'hello' LIKE 'h%',
    -- Ends with 'o'
    f2 := 'hello' LIKE '%o',
    -- Contains 'll'
    f3 := 'hello' LIKE '%ll%',
    -- Single character wildcard
    f4 := 'hello' LIKE 'h_llo',
    -- No match
    f5 := 'hello' LIKE 'world',
    -- Case sensitive
    f6 := 'hello' LIKE 'HELLO'
;
Result
f1 BOOLEANf2 BOOLEANf3 BOOLEANf4 BOOLEANf5 BOOLEANf6 BOOLEAN
truetruetruetruefalsefalse

NULL handling

FeatureQL
RETURN
    -- NULL string
    f1 := NULL::VARCHAR LIKE 'pattern',
    -- NULL pattern
    f2 := 'text' LIKE NULL::VARCHAR
;
Result
f1 BOOLEANf2 BOOLEAN
NULLNULL

Advanced patterns

FeatureQL
RETURN
    -- File extension
    f1 := 'file.txt' LIKE '%.txt',
    -- Escaped percent
    f2 := '100%' LIKE '100\%'
;
Result
f1 BOOLEANf2 BOOLEAN
truetrue

LIKE — functional call

FeatureQL
RETURN
    -- `LIKE(expr, pattern)` matches keyword `LIKE`
    f1 := LIKE('ab', 'a%')
;
Result
f1 BOOLEAN
true

LIKE — chained

FeatureQL
RETURN
    -- Receiver is the string; argument is the pattern
    f1 := ('ab').LIKE('a%')
;
Result
f1 BOOLEAN
true