Skip to content

Latest commit

 

History

History
105 lines (84 loc) · 2.61 KB

File metadata and controls

105 lines (84 loc) · 2.61 KB
description
Tests whether an expression matches one or more patterns. Comparisons are case-sensitive.

LIKE

Syntax

expression [ NOT ] LIKE pattern → boolean

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

Examples

{% code title="LIKE example" %}

SELECT 'pancake' LIKE '%cake'
-- True

{% endcode %}

{% code title="LIKE example" %}

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

{% endcode %}

expression [ NOT ] LIKE pattern ESCAPE escape_character → boolean

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

Examples

{% code title="LIKE example" %}

SELECT '50%_Off' LIKE '%50!%%' ESCAPE '!'
-- True

{% endcode %}

{% code title="LIKE example" %}

SELECT '%SalesData%/Users/Jane' NOT LIKE '/%SalesData/%//Users/%' ESCAPE '/'
-- False

{% endcode %}

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

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

Examples

{% code title="LIKE example" %}

SELECT 'Spark' LIKE ALL ('_park', '%ark')
-- True

{% endcode %}

{% code title="LIKE example" %}

SELECT 'Spark' NOT LIKE ALL ('_park', '%ark')
-- False

{% endcode %}

{% code title="LIKE example" %}

SELECT 'Spark' LIKE SOME ('meow', 'woof')
-- False

{% endcode %}

{% code title="LIKE example" %}

SELECT 'Spark' NOT LIKE SOME ('meow', 'woof')
-- True

{% endcode %}

{% code title="LIKE example" %}

SELECT 'Spark' LIKE ANY ('_park', '_mart')
-- True

{% endcode %}

{% code title="LIKE example" %}

SELECT 'Spark' NOT LIKE ANY ('_park', '_mart')
-- False

{% endcode %}