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.

Syntax

ENDSWITH( <expr1> , <expr2> )

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:samp:{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 work with the following collation specifications:

  • lower

  • upper

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

Examples

SELECT * FROM strings;

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

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

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

The following example uses ENDSWITH with collation:

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