A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/developer-guide/python-connector/../../sql-reference/functions/like below:

Website Navigation


[ NOT ] LIKE | Snowflake Documentation

Categories:

String & binary functions (Matching/Comparison)

[ NOT ] LIKE

Performs a case-sensitive comparison to determine whether a string matches or does not match a specified pattern. For case-insensitive matching, use ILIKE instead.

LIKE, ILIKE, and RLIKE all perform similar operations. However, RLIKE uses POSIX ERE (Extended Regular Expression) syntax instead of the SQL pattern syntax used by LIKE and ILIKE.

Tip

You can use the search optimization service to improve the performance of queries that call this function. For details, see Search Optimization Service.

See also:

[ NOT ] ILIKE , [ NOT ] RLIKE , LIKE ALL, LIKE ANY

Syntax
<subject> [ NOT ] LIKE <pattern> [ ESCAPE <escape> ]

LIKE( <subject> , <pattern> [ , <escape> ] )

Copy

Arguments

Required:

subject

Subject to match. This is typically a VARCHAR, although some other data types can be used.

pattern

Pattern to match. This is typically a VARCHAR, although some other data types can be used.

Optional:

escape

Character(s) inserted in front of a wildcard character to indicate that the wildcard should be interpreted as a regular character and not as a wildcard.

Returns

Returns a BOOLEAN or NULL.

Usage notes Collation details

Only the upper, lower, and trim collation specifications are supported. Combinations with upper, lower, and trim are also supported (for example, upper-trim and lower-trim), except for locale combinations (for example, en-upper).

Examples

Create a table that contains some strings:

CREATE OR REPLACE TABLE like_ex(name VARCHAR(20));
INSERT INTO like_ex VALUES
  ('John  Dddoe'),
  ('John \'alias\' Doe'),
  ('Joe   Doe'),
  ('John_down'),
  ('Joe down'),
  ('Elaine'),
  (''),    -- empty string
  (null);

Copy

The following examples show the use of LIKE, NOT LIKE, and the wildcard character %:

SELECT name
  FROM like_ex
  WHERE name LIKE '%Jo%oe%'
  ORDER BY name;

Copy

+------------------+
| NAME             |
|------------------|
| Joe   Doe        |
| John  Dddoe      |
| John 'alias' Doe |
+------------------+
SELECT name
  FROM like_ex
  WHERE name NOT LIKE '%Jo%oe%'
  ORDER BY name;

Copy

+-----------+
| NAME      |
|-----------|
|           |
| Elaine    |
| Joe down  |
| John_down |
+-----------+
SELECT name
  FROM like_ex
  WHERE name NOT LIKE 'John%'
  ORDER BY name;

Copy

+-----------+                                                                   
| NAME      |
|-----------|
|           |
| Elaine    |
| Joe   Doe |
| Joe down  |
+-----------+
SELECT name
  FROM like_ex
  WHERE name NOT LIKE ''
  ORDER BY name;

Copy

+------------------+
| NAME             |
|------------------|
| Elaine           |
| Joe   Doe        |
| Joe down         |
| John  Dddoe      |
| John 'alias' Doe |
| John_down        |
+------------------+

The following example uses a backslash to escape a single quote so that it can be found in pattern matching:

SELECT name
  FROM like_ex
  WHERE name LIKE '%\'%'
  ORDER BY name;

Copy

+------------------+
| NAME             |
|------------------|
| John 'alias' Doe |
+------------------+

The following examples use an ESCAPE clause:

SELECT name
  FROM like_ex
  WHERE name LIKE '%J%h%^_do%' ESCAPE '^'
  ORDER BY name;

Copy

+-----------+                                                                   
| NAME      |
|-----------|
| John_down |
+-----------+

Insert more rows into the like_ex table:

INSERT INTO like_ex (name) VALUES 
  ('100 times'),
  ('1000 times'),
  ('100%');

Copy

Without the escape character, the percent sign (%) is treated as a wildcard:

SELECT * FROM like_ex WHERE name LIKE '100%'
  ORDER BY 1;

Copy

+------------+                                                                  
| NAME       |
|------------|
| 100 times  |
| 100%       |
| 1000 times |
+------------+

With the escape character, the percent sign (%) is treated as a literal:

SELECT * FROM like_ex WHERE name LIKE '100^%' ESCAPE '^'
  ORDER BY 1;

Copy

+------+                                                                        
| NAME |
|------|
| 100% |
+------+

The following example uses an ESCAPE clause in which the backslash is the escape character. Note that the backslash itself must be escaped in both the ESCAPE clause and in the expression:

SELECT * FROM like_ex WHERE name LIKE '100\\%' ESCAPE '\\'
  ORDER BY 1;

Copy

+------+                                                                        
| NAME |
|------|
| 100% |
+------+

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4