Skip to main content
Version: current [25.x]

Categories: String

LIKE

Tests whether an expression matches one or more patterns. Comparisons are case-sensitive.

Syntax

expression [ NOT ] LIKE pattern → boolean

  • expression: The expression to compare.
  • NOT (optional): A keyword that inverts the return value.
  • pattern: The pattern that is compared to the expression.

Examples

LIKE example
SELECT 'pancake' LIKE '%cake'
-- True
LIKE example
SELECT 'pancake' NOT LIKE '%cake'
-- False

expression [ NOT ] LIKE pattern ESCAPE escape_character → boolean

  • expression: The expression to compare.
  • NOT (optional): A keyword that inverts the return value.
  • pattern: The pattern that is compared to the expression.
  • escape_character (optional): Putting escape_character before a wildcard in pattern makes LIKE treat the wildcard as a regular character when it appears in expression.

Examples

LIKE example
SELECT '50%_Off' LIKE '%50!%%' ESCAPE '!'
-- True
LIKE example
SELECT '%SalesData%/Users/Jane' NOT LIKE '/%SalesData/%//Users/%' ESCAPE '/'
-- False

expression [ NOT ] LIKE { ANY | SOME | ALL } ( [ pattern [, ...] ] ) → boolean

  • expression: A STRING expression.
  • NOT (optional): A keyword that inverts the return value.
  • ANY or SOME or ALL (optional): Keywords indicating whether the expression must match at least one pattern or must match all patterns.
  • pattern: One or more STRING expressions.

Examples

LIKE example
SELECT 'Spark' LIKE ALL ('_park', '%ark')
-- True
LIKE example
SELECT 'Spark' NOT LIKE ALL ('_park', '%ark')
-- False
LIKE example
SELECT 'Spark' LIKE SOME ('meow', 'woof')
-- False
LIKE example
SELECT 'Spark' NOT LIKE SOME ('meow', 'woof')
-- True
LIKE example
SELECT 'Spark' LIKE ANY ('_park', '_mart')
-- True
LIKE example
SELECT 'Spark' NOT LIKE ANY ('_park', '_mart')
-- False