Applies to VAST Cluster 5.5.
Functions › Search and split › Searching. Returns true if a string ends with a given suffix. suffix is the same function, and the Query Engine rewrites LIKE '%ab' to it.
Syntax
ends_with(s, suffix)
suffix(s, suffix)
| Argument | Type | Description |
|---|---|---|
s |
VARCHAR |
The string to test. |
suffix |
VARCHAR |
The text s must end with. |
Returns: BOOLEAN.
Aliases: suffix.
Set up the examples
The examples connect with the ADBC driver, as in VAST Query Engine (ADBC), and work in a schema called docs_sql_fn_string_ends_with. Set QE_ENDPOINT, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and VASTDB_BUCKET (SQL reference), and run the blocks in order in one Python session. Below each block is the output you should see.
This block connects, defines the run() and plan() helpers, and creates a table of four files. Rows 2 and 3 hold the same word, café, with the accent written two ways: as one character (U+00E9) and as e followed by a combining accent (U+0301). The last row has no values:
import os
import re
import adbc_driver_manager
import adbc_driver_manager.dbapi as dbapi
import adbc_driver_vastdb
BUCKET = os.environ["VASTDB_BUCKET"]
SCHEMA = f'"{BUCKET}/docs_sql_fn_string_ends_with"'
conn = dbapi.connect(
driver=adbc_driver_vastdb.get_driver_path(),
db_kwargs={
"vast.db.endpoint": os.environ["QE_ENDPOINT"],
"vast.db.access_key": os.environ["AWS_ACCESS_KEY_ID"],
"vast.db.secret_key": os.environ["AWS_SECRET_ACCESS_KEY"],
},
autocommit=True,
)
def server_message(e):
"""The server's message in a driver error, without the request ID or the echoed statement."""
text = re.sub(r"\[req=0x[0-9a-f]+\]: ", "", str(e))
found = (re.search(r'message: "(.*?)", request_id', text, re.S)
or re.search(r"description: (.*)\)", text, re.S))
message = found.group(1) if found else text.strip().splitlines()[-1]
message = re.sub(r"^Plan query: '.*?' failed with: ", "", message, flags=re.S)
message = re.split(r"\\n|\n", message)[0].replace('\\"', '"')
return message.replace(BUCKET, "<bucket>")
def run(sql):
"""Run one statement. Print the rows it returns, or the error."""
try:
with conn.cursor() as cur:
cur.execute(sql)
rows = cur.fetchall() if cur.description else []
except (adbc_driver_manager.Error, OSError) as e:
print(f"{type(e).__name__}: {server_message(e)}")
else:
print(rows)
def plan(sql):
"""Print the plan without its ~N Rows lines: the table's row count, which can still be 0 just after an insert."""
with conn.cursor() as cur:
cur.execute("EXPLAIN " + sql)
steps = cur.fetchall()[0][1]
print("\n".join(line for line in steps.splitlines() if "Rows" not in line))
TABLE = f"{SCHEMA}.files"
run(f"CREATE SCHEMA IF NOT EXISTS {SCHEMA}")
run(f"CREATE TABLE IF NOT EXISTS {TABLE} (id BIGINT, path VARCHAR, note VARCHAR)")
run(f"INSERT INTO {TABLE} VALUES "
"(1, '/logs/app/2026-10-13.log', 'Disk full'), "
"(2, '/logs/db/2026-10-12.log', 'menu caf\u00e9'), "
"(3, '/tmp/load_50%.csv', 'menu cafe\u0301'), "
"(4, NULL, NULL)")
[]
[]
[(4,)]
What it does
ends_with(s, suffix) is true when the last characters of s are exactly suffix. The comparison is code point by code point:
- Case matters.
ends_with('abC', 'c')is false. To ignore case, testlower(s)(lower) or use ILIKE'%ab'. - Wildcards and spaces are plain characters.
ends_with('a%', '%')is true;ends_with('abc ', 'c')is false because of the trailing space. - Accents must be written the same way.
ends_with('cafe\u0301', 'é')(a decomposedéin the string, a precomposed one in the suffix) is false, andends_with('cafe\u0301', '\u0301')is true: the string ends with the combining accent. Normalise the column with nfc_normalize when its text may be written either way. - An empty suffix matches every string, including the empty string.
NULLs and edge cases
| Input | Result |
|---|---|
ends_with(NULL, 'ld'), ends_with('abc', NULL) |
NULL |
ends_with('abc', ''), ends_with('', '') |
true |
ends_with('', 'a') |
false |
ends_with('abc', 'zabc') (suffix longer than the string) |
false |
ends_with('abC', 'c') |
false |
ends_with('abc ', 'c') (trailing space) |
false |
ends_with('a%', '%') |
true |
ends_with('café', 'é') (both precomposed) |
true |
ends_with('cafe\u0301', 'é') (decomposed string, precomposed suffix) |
false |
ends_with('cafe\u0301', '\u0301') (the combining accent alone) |
true |
ends_with('x🇫🇷', '🇷') (the second half of a flag emoji) |
true |
A number, date, boolean, BLOB or list on either side |
Error: No function matches the given name and argument types |
The same cases, as the cluster returns them. They use the table and helpers from Set up the examples:
run("SELECT ends_with(NULL, 'ld'), ends_with('abc', NULL), ends_with('abc', ''), ends_with('', ''), "
"ends_with('', 'a'), ends_with('abc', 'zabc')")
run("SELECT ends_with('abC', 'c'), ends_with('abc ', 'c'), ends_with('a%', '%')")
run("SELECT ends_with('caf\u00e9', '\u00e9'), ends_with('cafe\u0301', '\u00e9'), ends_with('cafe\u0301', '\u0301'), "
"ends_with('x\U0001F1EB\U0001F1F7', '\U0001F1F7')")
run("SELECT ends_with(123, 'ld')")
[(None, None, True, True, False, False)]
[(False, False, True)]
[(True, False, True, True)]
InternalError: Binder Error: No function matches the given name and argument types 'ends_with(INTEGER_LITERAL, STRING_LITERAL)'. You might need to add explicit type casts.
Examples
Test each path for a file extension with both spellings. The row with no path gives NULL:
run(f"SELECT id, ends_with(path, '.log'), suffix(path, '.csv') FROM {TABLE} ORDER BY id LIMIT 10")
[(1, True, False), (2, True, False), (3, False, True), (4, None, None)]
Keep the log files:
run(f"SELECT id, path FROM {TABLE} WHERE ends_with(path, '.log') ORDER BY id LIMIT 10")
[(1, '/logs/app/2026-10-13.log'), (2, '/logs/db/2026-10-12.log')]
Rows 2 and 3 both end with café on screen, but only row 2 matches a precomposed suffix until the column is normalised:
run(f"SELECT id, ends_with(note, 'caf\u00e9'), ends_with(nfc_normalize(note), 'caf\u00e9') FROM {TABLE} "
"ORDER BY id LIMIT 10")
[(1, False, False), (2, True, True), (3, False, True), (4, None, None)]
How it runs in VAST
The Query Engine runs on the cluster's CNodes, and a query on a table starts with a scan in VAST DataBase (VAST_SCAN). VAST DataBase can evaluate a comparison of a column with a constant, but not a function of a column, so ends_with() is always computed by the Query Engine:
- In the
SELECTlist, the scan reads the column and the Query Engine computesends_with()for each row it returns. - In
WHERE, the scan sends the column for every row, and aFILTERstep in the Query Engine keeps the rows that match. No rows are skipped in storage.
LIKE '%ab' and regexp_matches(s, 'ab$') are rewritten to suffix(s, 'ab'), so they run the same way. The plans show the FILTER step above the scan:
plan(f"SELECT id FROM {TABLE} WHERE ends_with(path, '.log')")
plan(f"SELECT id FROM {TABLE} WHERE path LIKE '%.log'")
┌───────────────────────────┐
│ PROJECTION │
│ ──────────────────── │
│ #1 │
│ │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│ FILTER │
│ ──────────────────── │
│ ends_with(path, '.log') │
│ │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│ VAST_SCAN │
│ ──────────────────── │
│ Function: VAST_SCAN │
│ │
│ Projections: │
│ path │
│ id │
│ │
└───────────────────────────┘
┌───────────────────────────┐
│ PROJECTION │
│ ──────────────────── │
│ #1 │
│ │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│ FILTER │
│ ──────────────────── │
│ suffix(path, '.log') │
│ │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│ VAST_SCAN │
│ ──────────────────── │
│ Function: VAST_SCAN │
│ │
│ Projections: │
│ path │
│ id │
│ │
└───────────────────────────┘
Make it faster
- Store what you filter on. If you often filter on a file extension, write it to its own column when you load the rows:
ext = 'log'is pushed down to VAST DataBase, so rows that don't match never leave storage. The plan for a raw column compared with a constant has noFILTERstep:
plan(f"SELECT id FROM {TABLE} WHERE path = '/logs/app/2026-10-13.log'")
┌───────────────────────────┐
│ VAST_SCAN │
│ ──────────────────── │
│ Function: VAST_SCAN │
│ Projections: id │
│ │
└───────────────────────────┘
- Combine it with a pushed-down condition. In
id > 1 AND ends_with(path, '.log'),id > 1is still evaluated in VAST DataBase, soends_with()runs only on the rows that pass it. LIKE '%ab'isn't faster. It becomes the samesuffix()call.
Limitations and errors
- Strings only. A number, a date, a boolean, a
BLOBor a list on either side fails withNo function matches the given name and argument types, for example'ends_with(INTEGER_LITERAL, STRING_LITERAL)'. Cast the value toVARCHARfirst. - No
endswith. The name without the underscore fails withScalar Function with name endswith does not exist!. Useends_with. - Exact code points. See What it does for case and accents.
run("SELECT ends_with(CAST(2026 AS VARCHAR), '26')")
run("SELECT endswith('abc', 'c')")
[(True,)]
InternalError: Catalog Error: Scalar Function with name endswith does not exist!
Similar functions
| Function | Tests | Where it runs in WHERE |
|---|---|---|
ends_with, suffix |
the end of the string | FILTER step |
LIKE '%ld' |
the same; rewritten to suffix() |
FILTER step |
regexp_matches (s, 'ld$') |
the same; rewritten to suffix() |
FILTER step |
| starts_with | the beginning of the string | FILTER step |
| contains | anywhere in the string | FILTER step |
right (s, n) = suffix |
the last n code points, compared |
FILTER step |
run("SELECT ends_with('Hello World', 'ld'), suffix('Hello World', 'ld'), 'Hello World' LIKE '%ld', "
"regexp_matches('Hello World', 'ld$'), right('Hello World', 2) = 'ld'")
run("SELECT starts_with('Hello World', 'He'), contains('Hello World', 'o W')")
[(True, True, True, True, True)]
[(True, True)]
Clean up:
run(f"DROP TABLE IF EXISTS {TABLE}")
run(f"DROP SCHEMA IF EXISTS {SCHEMA}")
conn.close()
[]
[]
See also
- Search and split: all the search functions.
- Where filters run and pushdowns.
- EXPLAIN: how to read a plan.