uppercase()#
relationalai.std.strings
#uppercase(string: str|Producer) -> Expression
Converts a string to uppercase.
If string
is a Producer
, then uppercase()
acts as a filter and removes non-string values from the producer.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
string | Producer or Python str object | The string to convert to uppercase. |
Returns#
An Expression
object.
Example#
Use uppercase()
to convert a string to uppercase:
#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")
Person.add(id=3).set(name=-1) # Non-string name
# =======
# EXAMPLE
# =======
# Set a uppercase_name property equal to the name property converted to uppercase.
with model.rule():
person = Person()
person.set(uppercase_name=strings.uppercase(person.name))
# Since uppercase() filters out non-string values, the uppercase_name property
# is not set for the person with id=3.
with model.query() as select:
person = Person()
response = select(person.id, person.uppercase_name)
print(response.results)
# id uppercase_name
# 0 1 ALICE
# 1 2 BOB
# 2 3 NaN