like()#
relationalai.std.strings
#like(string: str | Producer, pattern: str | Producer) -> Expression
Checks if a string matches a SQL LIKE pattern.
The %
character acts as a wildcard, matching any sequence of characters.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
string | str or Producer | The string to match against. |
pattern | str or Producer | A SQL LIKE pattern. |
Returns#
An Expression
object.
Example#
#import relationalai as rai
from relationalai.std.strings import like
# 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 contains 'li'.
with model.query() as select:
person = Person()
like(person.name, "%li%")
response = select(person.name)
print(response.results)
# Output:
# name
# 0 Alice