# ends_with

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: ends_with
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/string-functions/ends-with
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/string-functions/ends-with.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/string-functions/ends-with.adoc
description: The `ends_with()` function determines whether the first argument ends with a specified string in the second argument or not.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/ends-with.md -->

The `ends_with()` function determines whether the first argument ends with a specified string in the second argument or not.

```sql
ENDS_WITH(first_argument, 'second_argument')
```

-   `first_argument`: The search reference. Can be a string or a column name.

-   `second_argument`: The specified argument, which will have the search keywords.


The input type will be `STRING`, and the return type is `bool`, shown as `true` or `false`.

**Special case:**

-   Returns `NULL` for the `NULL` record.

-   Returns `true` (including the `NULL` record) if the `second_argument` is not specified.


## [](#examples)Examples

### [](#ends_with-function-using-column)`ends_with()` function using column

Consider a table named **courses**:

```sql
CREATE TABLE courses (
  course_id int,
  course_name text,
  credits text
);
INSERT INTO courses
    (course_id, course_name, credits)
VALUES
    (2111,'Basics of Plant Biotechnology',2),
    (2102,'Biochemistry',3),
    (1241,'Statistics',3),
    (4142,'Microbial Biodiversity',2),
    (3262,'Introduction to Plant Pathology',3),
    (3233,'Enzyme Technology',2),
    (1201,'Rural Sociology',2);
```

```sql
SELECT * FROM courses;
```

The query displays the table:

```sql
+------------+----------------------------------+-----------+
| course_id  | course_name                      | credits   |
+------------+----------------------------------+-----------+
| 2111       | Basics of Plant Biotechnology    | 2         |
| 2102       | Biochemistry                     | 3         |
| 1241       | Statistics                       | 3         |
| 4142       | Microbial Biodiversity           | 2         |
| 3262       | Introduction to Plant Pathology  | 3         |
| 3233       | Enzyme Technology                | 2         |
| 1201       | Rural Sociology                  | 2         |
+------------+----------------------------------+-----------+
```

This query checks which values of the **course\_name** column end with “ology” in the preceding table:

```sql
SELECT course_name, ENDS_WITH(course_name, 'ology') FROM courses;
```

This returns true to all the courses with the name ending with **ology.** Otherwise\*,\* `false`.

```sql
+----------------------------------+-------------+
| course_name                      | ends_with   |
+----------------------------------+-------------+
| Basics of Plant Biotechnology    | true        |
| Biochemistry                     | false       |
| Statistics                       | false       |
| Microbial Biodiversity           | false       |
| Introduction to Plant Pathology  | true        |
| Enzyme Technology                | true        |
| Rural Sociology                  | true        |
+----------------------------------+-------------+
```

### [](#ends_with-function-with-no-specified-argument)`ends_with()` function with no specified argument

The **patients\_data** table has a `NULL` value in the **allergies** column:

```sql
CREATE TABLE patients_data (
  record_number int,
  patient_name text,
  height_in_cm int,
  weight_in_kg int,
  allergies text
);
INSERT INTO patients_data
    (record_number, patient_name, height_in_cm, weight_in_kg, allergies)
VALUES
    (2009000908,'Vivienne Desjardin',168,49,NULL),
    (2012000876,'Elizabeth Reinhard',163,55,NULL),
    (2015000965,'James McCarthy',188,70,'penicillin'),
    (2020000109,'Jose Ramirez',170,70,'sulfonamide'),
    (2020000222,'Stefani Ricci',170,70,'peniccilin');
```

```sql
SELECT * FROM patients_data;
```

```sql
+----------------+---------------------+---------------+--------------+-------------+
| record_number  | patient_name        | height_in_cm  | weight_in_kg | allergies   |
+----------------+---------------------+---------------+--------------+-------------+
| 2009000908     | Vivienne Desjardin  | 168           | 49           | null        |
| 2012000876     | Elizabeth Reinhard  | 163           | 55           | null        |
| 2015000965     | James McCarthy      | 188           | 70           | penicillin  |
| 2020000109     | Jose Ramirez        | 170           | 70           | sulfonamide |
| 2020000222     | Stefani Ricci       | 170           | 70           | peniccilin  |
+----------------+---------------------+---------------+--------------+-------------+
```

For example, run the `ends_with` function but with no specified `second_argument`:

```sql
SELECT allergies, ENDS_WITH(allergies, '') FROM patients_data;
```

The result shows that `ends_with` returns true for all records (even the `NULL` one):

```sql
+--------------+--------------+
| allergies    | ends_with    |
+--------------+--------------+
| null         | true         |
| null         | true         |
| penicillin   | true         |
| sulfonamide  | true         |
| peniccilin   | true         |
+--------------+--------------+
```