ends_with()#

relationalai.std.strings
ends_with(string: Producer, suffix: str | Producer) -> Expression

Checks if a string ends with a suffix. Must be called in a rule or query context.

Parameters#

NameTypeDescription
stringProducerA producer that produces string values.
suffixstr or ProducerThe substring to check for.

Returns#

An Expression object.

Example#

import relationalai as rai
from relationalai.std.strings import ends_with

# Create a model named "people" with a Person type.
model = rai.Model("people")
Person = model.Type("Person")

# Add some people to the model.
with model.rule():
    alice = Person.add(name="Alice")
    bob = Person.add(name="Bob")

# Get all people whose name ends with "ice".
with model.query() as select:
    person = Person()
    ends_with(person.name, "Ali")
    response = select(person.name)

print(response.results)
# Output:
#     name
# 0  Alice

# The `substring` argument can also be a Producer.
with model.query() as select:
    sub = Person(name="Bob").name
    person = Person()
    ends_with(person.name, sub)
    response = select(person.name)

print(response.results)
# Output:
#    name
# 0   Bob

See Also#