contains

Tests whether a string contains another string.

Syntax

contains(<string>, <substring>)

Arguments

ArgumentTypeDescription
<string>stringString to test.
<substring>stringSubstring to match.

Returns

Returns boolean: TRUE if <string> contains <substring>, otherwise FALSE. Returns NULL if either input is NULL. An empty <substring> matches every non-NULL string.

Examples

Check which messages contain the exact lowercase substring payment.

VALUES ('payment failed'), ('repayment posted'), ('Payment declined')
SELECT $0 AS message
SELECT message, contains(message, 'payment') AS has_fragment
+------------------+--------------+
| message          | has_fragment |
+------------------+--------------+
| payment failed   | true         |
| repayment posted | true         |
| Payment declined | false        |
+------------------+--------------+

Substring matching also finds payment inside repayment and is case-sensitive. Use search when you want analyzed words instead.