like operator (Databricks SQL)

Returns true if str matches pattern with escape.

Syntax

str [ NOT ] like ( pattern [ ESCAPE escape ] )

Arguments

  • str: A STRING expression.

  • pattern: A STRING expression.

  • escape: A single character STRING literal.

Returns

A BOOLEAN.

The pattern is a string which is matched literally, with exception to the following special symbols:

  • _ matches any one character in the input (similar to . in POSIX regular expressions)

  • % matches zero or more characters in the input (similar to .* in POSIX regular expressions).

The default escape character is the '\'. If an escape character precedes a special symbol or another escape character, the following character is matched literally. It is invalid to escape any other character.

String literals are unescaped. For example, in order to match '\abc', the pattern should be '\\abc'.

str NOT like ... is equivalent to NOT(str like ...).

Examples

> SELECT like('Spark', '_park');
true
> SELECT '%SystemDrive%\\Users\\John' like '\%SystemDrive\%\\\\Users%';
true
> SELECT '%SystemDrive%/Users/John' like '/%SystemDrive/%//Users%' ESCAPE '/';
true