join()#

relationalai.std.strings
join(strings: Sequence[str | Producer], separator: str | Producer) -> Expression

Joins a sequence of strings into a single string using a separator. Must be called in a rule or query context.

Parameters#

NameTypeDescription
stringsSequence of str or Producer objects.A sequence, such as a list or tuple, of strings to be joined.
separatorstr or ProducerThe string to use as the separator value.

Returns#

An Expression object.

Example#

import relationalai as rai
from relationalai.std.strings import join

# 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(first="Alice", last="Smith")
    bob = Person.add(first="Bob", last="Jones")

# Join the first and last names of all people separated by a space.
with model.query() as select:
    person = Person()
    full_name = join([person.first, person.last], " ")
    response = select(full_name)

print(response.results)
# Output:
#              v
# 0  Alice Smith
# 1    BobJ ones

The sequence of strings to join can have any length.

See Also#