LIKE

Pattern-matching conditions

circle-info

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentationarrow-up-right

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected]envelope.

Thank you for your understanding.

Description

The LIKE operator compares a string expression, such as a column name, with a pattern that uses the wildcard characters % (percent) and _ (underscore). LIKE pattern matching always covers the entire string. To match a sequence anywhere within a string, the pattern must start and end with a percent sign. (Redshift SQL Language reference LIKEarrow-up-right).

circle-check
circle-info

In Snowflake the cases where the escape character is not provided, the default Redshift escape character '\\' will be added for full equivalence.

Grammar Syntax

expression [ NOT ] LIKE | ILIKE pattern [ ESCAPE 'escape_char' ]

Sample Source Patterns

Setup data

CREATE TABLE like_ex(name VARCHAR(20));

INSERT INTO like_ex VALUES
  ('John  Dddoe'),
  ('Joe   Doe'),
  ('Joe   Doe '),
  (' Joe   Doe '),
  (' Joe \n Doe '),
  ('John_down'),
  ('Joe down'),
  ('Elaine'),
  (''),
  (null),
  ('1000 times'),
  ('100%');

Like

Input Code:

Output Code:

Not like

Input Code:

Output Code:

Escape characters

Input Code:

Output Code:

ILike

Input Code:

Output Code:

Operators

The following operators are translated as follows:

Redshift
Snowflake

~~

LIKE

!~~

NOT LIKE

~~*

ILIKE

!~~*

NOT ILIKE

Input Code:

Output Code:

Known Issues

  1. The behavior of fixed char types may differ. Click here for more information.

There are no known issues.

Last updated