starts_with()#

relationalai.std.strings
#starts_with(string: str|Producer, prefix: str|Producer) -> Expression

Checks if a string begins with a prefix. Must be called in a rule or query context.

Parameters#

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

Returns#

An Expression object.

Example#

#import relationalai as rai
from relationalai.std.strings import starts_with

# =====
# SETUP
# =====

# 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():
    Person.add(name="Alice")
    Person.add(name="Bob")

# =======
# EXAMPLE
# =======

# Get all people whose name starts with "A".
with model.query() as select:
    person = Person()
    starts_with(person.name, "A")
    response = select(person.name)

print(response.results)
#     name
# 0  Alice

See Also#