

# Pattern matching functions and operators

Use these operators and functions to test whether a string matches a `LIKE` or `GLOB` pattern, or whether it starts with, ends with, or contains another string.

The tests are case-sensitive, except `ILIKE`, `ilike_escape`, and `not_ilike_escape`, which ignore case.

## `^@` (starts with) operator
<a name="athena-duckdb-functions-string-starts-with-operator"></a>

Returns `true` if `search_string` is a prefix of `string`, and `false` if it is not. The comparison is case-sensitive, and `%` and `_` are ordinary characters, not wildcards. An empty `search_string` matches every string. If either argument is `NULL`, returns `NULL`.

`starts_with` is an alias of `^@`. Use it as a function: `starts_with({{string}}, {{search_string}})` returns the same result as `{{string}} ^@ {{search_string}}`.

### Syntax
<a name="athena-duckdb-functions-string-starts-with-operator-syntax"></a>

```sql
{{string}} ^@ {{search_string}}
starts_with({{string}}, {{search_string}})
```

### Arguments
<a name="athena-duckdb-functions-string-starts-with-operator-arguments"></a>

The `^@` (starts with) operator takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{search\_string}}**  
The prefix to look for, as a `VARCHAR` value.

### Return type
<a name="athena-duckdb-functions-string-starts-with-operator-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-starts-with-operator-examples"></a>

The following SQL query tests a prefix with the operator and with the `starts_with` function.

```sql
SELECT
    'abc' ^@ 'ab' AS operator_form,
    starts_with('abc', 'a') AS function_form
```

The query returns the following result.


| operator\_form | function\_form | 
| --- | --- | 
| `true` | `true` | 

The following SQL query shows that the match is case-sensitive, that an empty prefix always matches, that `%` is not a wildcard, and that a `NULL` input returns `NULL`.

```sql
SELECT
    starts_with('abc', 'A') AS upper_prefix,
    starts_with('abc', '') AS empty_prefix,
    starts_with('abc', 'a%') AS percent_prefix,
    starts_with(NULL, 'a') AS null_input
```

The query returns the following result.


| upper\_prefix | empty\_prefix | percent\_prefix | null\_input | 
| --- | --- | --- | --- | 
| `false` | `true` | `false` | `NULL` | 

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-string-starts-with-operator-differences-from-engine-version-3"></a>

Athena engine version 3 does not support the `^@` operator. For a query that runs on both engines, use the `starts_with` function.

## `contains` function
<a name="athena-duckdb-functions-string-contains"></a>

With a string, returns `true` if `search_value` appears anywhere in `value`. The search is case-sensitive and has no wildcards, and an empty `search_value` always matches.

With a list, returns `true` if `search_value` is an element of the list. A list that holds `NULL` but not `search_value` returns `false`, not `NULL`. With a `MAP`, returns `true` if `search_value` is one of the map's keys. With an unnamed struct, such as one built with `row`, returns `true` if one of its fields equals `search_value`.

If `value` or `search_value` is `NULL`, returns `NULL`, not `false`.

### Syntax
<a name="athena-duckdb-functions-string-contains-syntax"></a>

```sql
contains({{value}}, {{search_value}})
```

### Arguments
<a name="athena-duckdb-functions-string-contains-arguments"></a>

The `contains` function takes the following arguments:

**{{value}}**  
The value to search: a `VARCHAR` string, a list, a `MAP`, or an unnamed `STRUCT`.

**{{search\_value}}**  
What to look for: a `VARCHAR` substring for a string, an element for a list, a key for a map, or a field value for an unnamed struct.

### Return type
<a name="athena-duckdb-functions-string-contains-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-contains-examples"></a>

The following SQL query tests whether a string contains a letter.

```sql
SELECT contains('abc', 'a') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query shows that the search is case-sensitive, that an empty search string matches, and that `%` is not a wildcard.

```sql
SELECT
    contains('abc', 'A') AS upper_case,
    contains('abc', '') AS empty_search,
    contains('abc', 'a%') AS percent_search
```

The query returns the following result.


| upper\_case | empty\_search | percent\_search | 
| --- | --- | --- | 
| `false` | `true` | `false` | 

The following SQL query searches a list, a list that holds `NULL`, the keys of a map, and an unnamed struct.

```sql
SELECT
    contains([1, 2, 3], 2) AS in_list,
    contains([1, NULL], 3) AS list_with_null,
    contains(MAP {'a': 1, 'b': 2}, 'b') AS map_key,
    contains(row(1, 'x'), 'x') AS struct_field
```

The query returns the following result.


| in\_list | list\_with\_null | map\_key | struct\_field | 
| --- | --- | --- | --- | 
| `true` | `false` | `true` | `true` | 

The following SQL query casts the `NULL` literal to `VARCHAR`, so the string form runs and returns `NULL`. Without the cast, the query fails.

```sql
SELECT contains('abc', NULL::VARCHAR) AS result
```

The query returns the following result.


| result | 
| --- | 
| `NULL` | 

The following SQL query passes an untyped `NULL` literal as `search_value` to the list, map, and struct forms. Each form returns `NULL`.

```sql
SELECT
    contains([1, 2, 3], NULL) AS list_form,
    contains(MAP {'a': 1}, NULL) AS map_form,
    contains(row(1, 'x'), NULL) AS struct_form
```

The query returns the following result.


| list\_form | map\_form | struct\_form | 
| --- | --- | --- | 
| `NULL` | `NULL` | `NULL` | 

### Considerations
<a name="athena-duckdb-functions-string-contains-considerations"></a>

With a string, an untyped `NULL` literal as `search_value`, as in `contains('abc', NULL)`, makes the query fail, because more than one form of the function matches. Cast the literal, for example `NULL::VARCHAR`. With a list, a map, or an unnamed struct, an untyped `NULL` literal works, and the result is `NULL`.

The struct form works only with unnamed structs. A struct with named fields causes an error.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-string-contains-differences-from-engine-version-3"></a>

In Athena engine version 3, `contains` on an array returns `NULL` when the array holds a `NULL` element and no match. In DuckDB, it returns `false`.

In Athena engine version 3, `contains` takes an array, not a string. To test for a substring in a query that runs on both engines, use `strpos({{value}}, {{search_value}}) > 0`.

## `GLOB` operator
<a name="athena-duckdb-functions-string-glob"></a>

Returns `true` if `string` matches `pattern`, and `false` if it does not. The pattern uses the wildcards of file-name matching and must match the whole string. In the pattern, `*` matches any sequence of zero or more characters, `?` matches exactly one character, and `[abc]` or `[a-c]` matches one character from a set or range. A negated set, such as `[!abc]`, matches one character that is not in the set. Matching is case-sensitive.

`NOT GLOB` returns the opposite result. If `string` or `pattern` is `NULL`, both forms return `NULL`. To match a literal `*`, `?`, or `[`, put it in brackets, such as `[*]`.

You can also write `GLOB` as the `~~~` operator.

### Syntax
<a name="athena-duckdb-functions-string-glob-syntax"></a>

```sql
{{string}} [ NOT ] GLOB {{pattern}}
{{string}} ~~~ {{pattern}}
```

### Arguments
<a name="athena-duckdb-functions-string-glob-arguments"></a>

The `GLOB` operator takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The pattern to match, as a `VARCHAR` value written with `*`, `?`, and bracket wildcards.

### Return type
<a name="athena-duckdb-functions-string-glob-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-glob-examples"></a>

The following SQL query tests file names against patterns that use `*` and `?`.

```sql
SELECT
    'data.csv' GLOB '*.csv' AS csv_file,
    'data.CSV' GLOB '*.csv' AS upper_case_name,
    'file1.csv' GLOB 'file?.csv' AS one_char
```

The query returns the following result.


| csv\_file | upper\_case\_name | one\_char | 
| --- | --- | --- | 
| `true` | `false` | `true` | 

The following SQL query uses a character range, a negated set, `NOT GLOB`, and a `NULL` input.

```sql
SELECT
    'b1' GLOB '[a-c][0-9]' AS in_range,
    'd1' GLOB '[!a-c]?' AS not_in_set,
    'data.csv' NOT GLOB '*.json' AS not_glob,
    NULL GLOB '*' AS null_input
```

The query returns the following result.


| in\_range | not\_in\_set | not\_glob | null\_input | 
| --- | --- | --- | --- | 
| `true` | `true` | `true` | `NULL` | 

The following SQL query matches a literal asterisk by putting it in brackets, and uses the `~~~` operator form.

```sql
SELECT
    'a*b' GLOB 'a[*]b' AS literal_star,
    'axb' GLOB 'a[*]b' AS other_char,
    'abc' ~~~ 'a*' AS glob_operator
```

The query returns the following result.


| literal\_star | other\_char | glob\_operator | 
| --- | --- | --- | 
| `true` | `false` | `true` | 

### Considerations
<a name="athena-duckdb-functions-string-glob-considerations"></a>

`GLOB` does not take an `ESCAPE` clause. Instead, a backslash in the pattern makes the next character match literally, so `'a*b' GLOB 'a\*b'` returns `true`. A backslash in the pattern does not match a backslash in the string, so `'a\b' GLOB 'a\b'` returns `false`. To match a literal backslash, put it in brackets, such as `[\]`.

To negate a set, use `[!abc]`. In `[^abc]`, the `^` is an ordinary member of the set, not a negation.

To match regardless of case, convert the string to lowercase and write the pattern in lowercase, for example `lower({{file_name}}) GLOB '*.csv'`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-string-glob-differences-from-engine-version-3"></a>

Athena engine version 3 does not support `GLOB`. For a pattern match that runs on both engines, use `LIKE`, with `%` in place of `*` and `_` in place of `?`. In `LIKE`, `%` and `_` are wildcards, so a `%` or `_` that the `GLOB` pattern matches literally needs an `ESCAPE` character. `LIKE` has no bracket sets such as `[a-c]`.

## `ILIKE` operator
<a name="athena-duckdb-functions-string-ilike"></a>

Returns `true` if `string` matches `pattern` when the case of letters is ignored, and `false` if it does not. The pattern must match the whole string, and it uses the same wildcards as `LIKE`: `%` matches any sequence of zero or more characters, and `_` matches exactly one character.

`NOT ILIKE` returns the opposite result. If `string` or `pattern` is `NULL`, both forms return `NULL`. To match a literal `%` or `_`, name an escape character with `ESCAPE`.

You can also write `ILIKE` as the `~~*` operator and `NOT ILIKE` as the `!~~*` operator.

### Syntax
<a name="athena-duckdb-functions-string-ilike-syntax"></a>

```sql
{{string}} [ NOT ] ILIKE {{pattern}} [ ESCAPE {{escape_character}} ]
{{string}} ~~* {{pattern}}
{{string}} !~~* {{pattern}}
```

### Arguments
<a name="athena-duckdb-functions-string-ilike-arguments"></a>

The `ILIKE` operator takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The pattern to match, as a `VARCHAR` value. Use `%` for any sequence of characters and `_` for one character.

**{{escape\_character}}**  
The escape character, a `VARCHAR` value of one character. In the pattern, this character makes the next `%`, `_`, or escape character match literally. An empty string means that there is no escape character. This argument is optional.

### Return type
<a name="athena-duckdb-functions-string-ilike-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-ilike-examples"></a>

The following SQL query compares `ILIKE` with `LIKE` on an uppercase string.

```sql
SELECT
    'ABC' ILIKE 'a%' AS ilike_result,
    'ABC' ILIKE 'a_c' AS three_chars,
    'ABC' LIKE 'a%' AS like_result
```

The query returns the following result.


| ilike\_result | three\_chars | like\_result | 
| --- | --- | --- | 
| `true` | `true` | `false` | 

The following SQL query uses `NOT ILIKE`, an escaped percent sign, and a `NULL` input.

```sql
SELECT
    'ABC' NOT ILIKE 'b%' AS not_ilike,
    '10% OFF' ILIKE '10!% off' ESCAPE '!' AS escaped_percent,
    NULL ILIKE 'a%' AS null_input
```

The query returns the following result.


| not\_ilike | escaped\_percent | null\_input | 
| --- | --- | --- | 
| `true` | `true` | `NULL` | 

The following SQL query uses the operator forms `~~*` and `!~~*`.

```sql
SELECT
    'ABC' ~~* 'a%' AS ilike_operator,
    'ABC' !~~* 'a%' AS not_ilike_operator
```

The query returns the following result.


| ilike\_operator | not\_ilike\_operator | 
| --- | --- | 
| `true` | `false` | 

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-string-ilike-differences-from-engine-version-3"></a>

Athena engine version 3 does not support `ILIKE`. For a match that ignores case and runs on both engines, use `lower({{string}}) LIKE lower({{pattern}})`.

## `ilike_escape` function
<a name="athena-duckdb-functions-string-ilike-escape"></a>

Tests whether `string` matches the `LIKE` pattern in `pattern`, ignoring case. The result is `true` for a match and `false` when there is no match. In the pattern, `%` matches any sequence of characters and `_` matches any single character. Put `escape_character` in front of `%`, `_`, or the escape character itself to match that character literally. If any argument is `NULL`, the result is `NULL`.

`ilike_escape({{string}}, {{pattern}}, {{escape_character}})` returns the same result as `{{string}} ILIKE {{pattern}} ESCAPE {{escape_character}}`. For a case-sensitive match, use the [`like_escape` function](#athena-duckdb-functions-string-like-escape).

### Syntax
<a name="athena-duckdb-functions-string-ilike-escape-syntax"></a>

```sql
ilike_escape({{string}}, {{pattern}}, {{escape_character}})
```

### Arguments
<a name="athena-duckdb-functions-string-ilike-escape-arguments"></a>

The `ilike_escape` function takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The `LIKE` pattern, as a `VARCHAR` value.

**{{escape\_character}}**  
The escape character, a `VARCHAR` value of one ASCII character. An empty string means that the pattern has no escape character.

### Return type
<a name="athena-duckdb-functions-string-ilike-escape-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-ilike-escape-examples"></a>

The following SQL query matches a literal percent sign, ignoring case. The pattern uses `$` as the escape character.

```sql
SELECT ilike_escape('A%c', 'a$%C', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query returns `false`, because the escaped `%` matches only a literal percent sign, not the letter `b`.

```sql
SELECT ilike_escape('Abc', 'a$%C', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

The following SQL query writes the same test with the `ILIKE` operator and an `ESCAPE` clause.

```sql
SELECT 'A%c' ILIKE 'a$%C' ESCAPE '$' AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

### Considerations
<a name="athena-duckdb-functions-string-ilike-escape-considerations"></a>

If `escape_character` is longer than one byte, the query fails. A non-ASCII character, such as `chr(228)`, is longer than one byte, so it cannot be the escape character.

If `pattern` ends with an `escape_character` that has no character after it to escape, the query fails.

## `LIKE` operator
<a name="athena-duckdb-functions-string-like"></a>

Returns `true` if `string` matches `pattern`, and `false` if it does not. The pattern must match the whole string. In the pattern, `%` matches any sequence of zero or more characters, and `_` matches exactly one character. Every other character matches only itself, and letters must match in case.

`NOT LIKE` returns the opposite result. If `string` or `pattern` is `NULL`, both forms return `NULL`. To match a literal `%` or `_`, name an escape character with `ESCAPE` and put it before the wildcard in the pattern.

You can also write `LIKE` as the `~~` operator and `NOT LIKE` as the `!~~` operator. For a match that ignores case, use `ILIKE`.

### Syntax
<a name="athena-duckdb-functions-string-like-syntax"></a>

```sql
{{string}} [ NOT ] LIKE {{pattern}} [ ESCAPE {{escape_character}} ]
{{string}} ~~ {{pattern}}
{{string}} !~~ {{pattern}}
```

### Arguments
<a name="athena-duckdb-functions-string-like-arguments"></a>

The `LIKE` operator takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The pattern to match, as a `VARCHAR` value. Use `%` for any sequence of characters and `_` for one character.

**{{escape\_character}}**  
The escape character, a `VARCHAR` value of one character. In the pattern, this character makes the next `%`, `_`, or escape character match literally. An empty string means that there is no escape character. This argument is optional.

### Return type
<a name="athena-duckdb-functions-string-like-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-like-examples"></a>

The following SQL query tests one string against a prefix pattern, a pattern of exactly three characters, and a pattern with no wildcards.

```sql
SELECT
    'abc' LIKE 'a%' AS starts_with_a,
    'abc' LIKE '_b_' AS three_chars,
    'abc' LIKE 'b' AS exact_b
```

The query returns the following result.


| starts\_with\_a | three\_chars | exact\_b | 
| --- | --- | --- | 
| `true` | `true` | `false` | 

The following SQL query shows that `LIKE` and `=` are both case-sensitive, that `NOT LIKE` returns the opposite result, and that a `NULL` input returns `NULL`.

```sql
SELECT
    'abc' LIKE 'A%' AS upper_pattern,
    'abc' NOT LIKE 'A%' AS not_like,
    'abc' = 'ABC' AS equals_upper,
    NULL LIKE 'a%' AS null_input
```

The query returns the following result.


| upper\_pattern | not\_like | equals\_upper | null\_input | 
| --- | --- | --- | --- | 
| `false` | `true` | `false` | `NULL` | 

The following SQL query uses `ESCAPE` to match a literal percent sign and a literal underscore. Without an `ESCAPE` clause, the backslash is an ordinary character.

```sql
SELECT
    '50% off' LIKE '50!%%' ESCAPE '!' AS escaped_percent,
    'a_c' LIKE 'a\_c' AS backslash_without_escape,
    'a_c' LIKE 'a\_c' ESCAPE '\' AS backslash_with_escape
```

The query returns the following result.


| escaped\_percent | backslash\_without\_escape | backslash\_with\_escape | 
| --- | --- | --- | 
| `true` | `false` | `true` | 

The following SQL query uses the operator forms `~~` and `!~~`.

```sql
SELECT
    'abc' ~~ 'a%' AS like_operator,
    'abc' !~~ 'a%' AS not_like_operator
```

The query returns the following result.


| like\_operator | not\_like\_operator | 
| --- | --- | 
| `true` | `false` | 

### Considerations
<a name="athena-duckdb-functions-string-like-considerations"></a>

`LIKE` has no default escape character. A backslash in the pattern matches a literal backslash unless you name it with `ESCAPE '\'`.

The `ESCAPE` value must be one character or an empty string. A longer value causes an error.

To test for a fixed prefix or substring without escaping wildcards, use the `^@` operator or the `contains` function.

## `like_escape` function
<a name="athena-duckdb-functions-string-like-escape"></a>

Tests whether `string` matches the `LIKE` pattern in `pattern`. The result is `true` for a match and `false` when there is no match. The match is case-sensitive. In the pattern, `%` matches any sequence of characters and `_` matches any single character. Put `escape_character` in front of `%`, `_`, or the escape character itself to match that character literally. If any argument is `NULL`, the result is `NULL`.

`like_escape({{string}}, {{pattern}}, {{escape_character}})` returns the same result as `{{string}} LIKE {{pattern}} ESCAPE {{escape_character}}`. To ignore case, use the [`ilike_escape` function](#athena-duckdb-functions-string-ilike-escape).

### Syntax
<a name="athena-duckdb-functions-string-like-escape-syntax"></a>

```sql
like_escape({{string}}, {{pattern}}, {{escape_character}})
```

### Arguments
<a name="athena-duckdb-functions-string-like-escape-arguments"></a>

The `like_escape` function takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The `LIKE` pattern, as a `VARCHAR` value.

**{{escape\_character}}**  
The escape character, a `VARCHAR` value of one ASCII character. An empty string means that the pattern has no escape character.

### Return type
<a name="athena-duckdb-functions-string-like-escape-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-like-escape-examples"></a>

The following SQL query matches a literal percent sign. The pattern uses `$` as the escape character.

```sql
SELECT like_escape('a%c', 'a$%c', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query tests whether strings start with `100%`, using `#` as the escape character. The unescaped `%` at the end of the pattern matches the rest of the string.

```sql
SELECT
    like_escape(
        '100% done', '100#%%', '#'
    ) AS percent_value,
    like_escape(
        '1000 done', '100#%%', '#'
    ) AS other_value
```

The query returns the following result.


| percent\_value | other\_value | 
| --- | --- | 
| `true` | `false` | 

The following SQL query shows that the match is case-sensitive.

```sql
SELECT like_escape('A%c', 'a$%c', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

### Considerations
<a name="athena-duckdb-functions-string-like-escape-considerations"></a>

If `escape_character` is longer than one byte, the query fails. A non-ASCII character, such as `chr(228)`, is longer than one byte, so it cannot be the escape character.

If `pattern` ends with an `escape_character` that has no character after it to escape, the query fails.

## `not_ilike_escape` function
<a name="athena-duckdb-functions-string-not-ilike-escape"></a>

Returns `true` if `string` does not match `pattern` when case is ignored, and `false` if it does. In the pattern, `%` matches any sequence of characters and `_` matches any single character. Put `escape_character` in front of `%`, `_`, or the escape character itself to match that character literally. If any argument is `NULL`, the result is `NULL`.

`not_ilike_escape({{string}}, {{pattern}}, {{escape_character}})` returns the same result as `{{string}} NOT ILIKE {{pattern}} ESCAPE {{escape_character}}`. For a case-sensitive test, use the [`not_like_escape` function](#athena-duckdb-functions-string-not-like-escape).

### Syntax
<a name="athena-duckdb-functions-string-not-ilike-escape-syntax"></a>

```sql
not_ilike_escape({{string}}, {{pattern}}, {{escape_character}})
{{string}} NOT ILIKE {{pattern}} ESCAPE {{escape_character}}
```

### Arguments
<a name="athena-duckdb-functions-string-not-ilike-escape-arguments"></a>

The `not_ilike_escape` function takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The `LIKE` pattern, as a `VARCHAR` value.

**{{escape\_character}}**  
The escape character, a `VARCHAR` value of one character. An empty string means that the pattern has no escape character.

### Return type
<a name="athena-duckdb-functions-string-not-ilike-escape-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-not-ilike-escape-examples"></a>

The following SQL query returns `false` because the string matches the pattern when case is ignored. The pattern uses `$` as the escape character, so `$%` matches only a literal percent sign.

```sql
SELECT not_ilike_escape('A%c', 'a$%C', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

The following SQL query returns `true` because the string has no percent sign for the escaped `%` to match.

```sql
SELECT not_ilike_escape('Abc', 'a$%c', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query runs the test from the first example with the `NOT ILIKE` operator and an `ESCAPE` clause.

```sql
SELECT 'A%c' NOT ILIKE 'a$%C' ESCAPE '$' AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

### Considerations
<a name="athena-duckdb-functions-string-not-ilike-escape-considerations"></a>

If `escape_character` is longer than one character, the query fails.

## `not_like_escape` function
<a name="athena-duckdb-functions-string-not-like-escape"></a>

Returns `true` if `string` does not match `pattern`, and `false` if it does. The match is case-sensitive. In the pattern, `%` matches any sequence of characters and `_` matches any single character. Put `escape_character` in front of `%`, `_`, or the escape character itself to match that character literally. If any argument is `NULL`, the result is `NULL`.

`not_like_escape({{string}}, {{pattern}}, {{escape_character}})` returns the same result as `{{string}} NOT LIKE {{pattern}} ESCAPE {{escape_character}}`. To ignore case, use the [`not_ilike_escape` function](#athena-duckdb-functions-string-not-ilike-escape).

### Syntax
<a name="athena-duckdb-functions-string-not-like-escape-syntax"></a>

```sql
not_like_escape({{string}}, {{pattern}}, {{escape_character}})
{{string}} NOT LIKE {{pattern}} ESCAPE {{escape_character}}
```

### Arguments
<a name="athena-duckdb-functions-string-not-like-escape-arguments"></a>

The `not_like_escape` function takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{pattern}}**  
The `LIKE` pattern, as a `VARCHAR` value.

**{{escape\_character}}**  
The escape character, a `VARCHAR` value of one character. An empty string means that the pattern has no escape character.

### Return type
<a name="athena-duckdb-functions-string-not-like-escape-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-not-like-escape-examples"></a>

The following SQL query returns `false` because the string matches the pattern. The pattern uses `$` as the escape character, so `$%` matches only a literal percent sign.

```sql
SELECT not_like_escape('a%c', 'a$%c', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

The following SQL query returns `true` because the match is case-sensitive, and `A` does not match `a`.

```sql
SELECT not_like_escape('A%c', 'a$%c', '$') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query runs the test from the first example with the `NOT LIKE` operator and an `ESCAPE` clause.

```sql
SELECT 'a%c' NOT LIKE 'a$%c' ESCAPE '$' AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

### Considerations
<a name="athena-duckdb-functions-string-not-like-escape-considerations"></a>

If `escape_character` is longer than one character, the query fails.

## `prefix` function
<a name="athena-duckdb-functions-string-prefix"></a>

Returns `true` if `string` begins with `search_string`, and `false` otherwise. The comparison is case-sensitive, and an empty `search_string` matches every string. If either argument is `NULL`, the result is `NULL`.

The `starts_with` function and the `^@` operator run the same test. To test the end of a string, use the [`suffix` function](#athena-duckdb-functions-string-suffix).

### Syntax
<a name="athena-duckdb-functions-string-prefix-syntax"></a>

```sql
prefix({{string}}, {{search_string}})
```

### Arguments
<a name="athena-duckdb-functions-string-prefix-arguments"></a>

The `prefix` function takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{search\_string}}**  
The string to look for at the start of `string`, as a `VARCHAR` value.

### Return type
<a name="athena-duckdb-functions-string-prefix-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-prefix-examples"></a>

The following SQL query tests whether a string starts with `ab`.

```sql
SELECT prefix('abc', 'ab') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query returns `false` because the comparison is case-sensitive.

```sql
SELECT prefix('abc', 'AB') AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

The following SQL query returns `true` because an empty search string matches every string.

```sql
SELECT prefix('abc', '') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

## `suffix` function
<a name="athena-duckdb-functions-string-suffix"></a>

Checks whether the last characters of `string` are the same as `search_string`, and returns `true` or `false`. The comparison is case-sensitive. An empty `search_string` matches every string. If either argument is `NULL`, the result is `NULL`.

`ends_with` is an alias of `suffix`. To test the start of a string, use the [`prefix` function](#athena-duckdb-functions-string-prefix) or `starts_with`.

### Syntax
<a name="athena-duckdb-functions-string-suffix-syntax"></a>

```sql
suffix({{string}}, {{search_string}})
```

### Arguments
<a name="athena-duckdb-functions-string-suffix-arguments"></a>

The `suffix` function takes the following arguments:

**{{string}}**  
The string to test, as a `VARCHAR` value.

**{{search\_string}}**  
The string to look for at the end of `string`, as a `VARCHAR` value.

### Return type
<a name="athena-duckdb-functions-string-suffix-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-string-suffix-examples"></a>

The following SQL query tests whether a string ends with `bc`.

```sql
SELECT suffix('abc', 'bc') AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query uses the `ends_with` alias. The comparison is case-sensitive, so `BC` does not match.

```sql
SELECT ends_with('abc', 'BC') AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 