Categories:

String & Binary Functions (Matching/Comparison)

ENDSWITH

Returns TRUE if the first expression ends with second expression. Both expressions must be text or binary expressions.

Tip

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

Syntax

ENDSWITH( <expr1> , <expr2> )
Copy

Arguments

expr1

The string to search in.

expr2

The string to search for at the end of expr1.

Returns

Returns a BOOLEAN. The value is TRUE if expr1 ends with expr2. Returns NULL if either input expression is NULL. Otherwise, returns FALSE.

Collation Details

The collation specifications of all input arguments must be compatible.

This function does not support the following collation specifications:

  • pi (punctuation-insensitive).

  • cs-ai (case-sensitive, accent-insensitive).

Note

To use this function with a column that has the upper or lower collation specifiers, the 2024_02 behavior change bundle must be enabled in your account. Currently, it is enabled by default.

If the 2024_02 behavior change bundle is disabled in your account, this function will not behave as documented.

To enable this bundle in your account, execute the following statement:

SELECT SYSTEM$ENABLE_BEHAVIOR_CHANGE_BUNDLE('2024_02');
Copy

Examples

SELECT * FROM strings;

---------+
    S    |
---------+
 coffee  |
 ice tea |
 latte   |
 tea     |
 [NULL]  |
---------+

SELECT * FROM strings WHERE ENDSWITH(s, 'te');

-------+
   S   |
-------+
 latte |
-------+
Copy

The following example uses ENDSWITH with collation:

SELECT ENDSWITH(COLLATE('ñn', 'sp'), COLLATE('n', 'sp'));
+---------------------------------------------------+
| ENDSWITH(COLLATE('ÑN', 'SP'), COLLATE('N', 'SP')) |
|---------------------------------------------------|
| True                                              |
+---------------------------------------------------+
Copy