relationalai.std.strings.starts_with()
starts_with(string: Producer, prefix: str|Producer) -> Expression
Filters values produced by a Producer
to only include strings that begin with a specified prefix. Must be called in a rule or query context.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”An Expression
object.
Example
Section titled “Example”Use starts_with()
to filter strings that start with a specified prefix:
import relationalai as raifrom 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 starts with "A".with model.query() as select: person = Person() strings.starts_with(person.name, "A") response = select(person.id, person.name)
print(response.results)# id name# 0 1 Alice
# Get all people whose name does not start with "A".with model.query() as select: person = Person() with model.not_found(): strings.starts_with(person.name, "A") response = select(person.id, person.name)
print(response.results)# id name# 0 2 Bob