Skip to content

relationalai.std.strings.like()

like(string: Producer, pattern: str|Producer) -> Expression

Filters values produced by a Producer to only include strings that match a specified SQL LIKE pattern. The % character acts as a wildcard, matching any sequence of characters. Must be called in a rule or query context.

NameTypeDescription
stringProducerThe string to match against.
patternstr or ProducerThe SQL LIKE pattern to match.

An Expression object.

Use like() to filter strings that match a specified SQL LIKE pattern:

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 contains 'li'.
with model.query() as select:
person = Person()
strings.like(person.name, "%li%")
response = select(person.id, person.name)
print(response.results)
# id name
# 0 1 Alice
# Get all people whose name does not contain 'li'.
with model.query() as select:
person = Person()
with model.not_found():
strings.like(person.name, "%li%")
response = select(person.id, person.name)
print(response.results)
# id name
# 0 2 Bob