Skip to content

relationalai.std.strings.ends_with()

ends_with(string: Producer, suffix: str|Producer) -> Expression

Filters values produced by a Producer to only include strings that end with a specified suffix. Must be called in a rule or query context.

NameTypeDescription
stringProducerThe string to check.
suffixstr or ProducerThe suffix to check for.

An Expression object.

Use ends_with() to filter strings that end with a specified suffix:

import relationalai as rai
from relationalai.std import strings
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Person = model.Type("Person")
with model.rule():
Person.add(id=1).set(name="Alice")
Person.add(id=2).set(name="Bob")
# ========
# EXAMPLES
# ========
# Get all people whose name ends with "ice".
with model.query() as select:
person = Person()
strings.ends_with(person.name, "ice")
response = select(person.id, person.name)
print(response.results)
# id name
# 0 1 Alice
# Get all people whose name does not end with "ice".
with model.query() as select:
person = Person()
with model.not_found():
strings.ends_with(person.name, "ice")
response = select(person.id, person.name)
print(response.results)
# id name
# 0 2 Bob