FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

til-3/postgres/string-contains-another-string.md at master · iCodeIN/til-3 · GitHub

/ til-3 Public
forked from jbranchaud/til

Latest commit

 

History

History
26 lines (20 loc) · 592 Bytes

File metadata and controls

26 lines (20 loc) · 592 Bytes

String Contains Another String

You can check if a string contains another string using the position function.

> select position('One' in 'One Two Three');
 position
----------
        1

It returns the 1-based index of the first character of the first match of that substring.

> select position('Four' in 'One Two Three');
 position
----------
        0

If the substring doesn't appear within the string, then the result is 0.

Thus, you can determine if a string contains another string by checking if the value resulting from position is greater than 0.


Back | FazBrowse Home | New Git URL