Skip to content

string_join

relationalai.semantics.std.aggregates
string_join(
*args: AggValue,
sep: str = "",
index: Value | list[Value] | tuple[Value, ...] | None = None
) -> Aggregate

Join string values with a separator, in ascending order.

.. versionchanged:: 1.27.0 string_join now returns a result; on earlier releases every call failed. index takes an ordering key, or a list of them, instead of being ignored, and the joined value must be a String.

The values are joined in ascending order of index, with the value itself as the final tiebreaker. Each distinct combination of ordering keys and value is joined once within each group (the whole population when there is no .per()); add a row-unique key such as an id to keep repeated values. A row contributes only when the value and every key are present, and a NaN Float key counts as absent.

Parameters

  • *args

    (AggValue, default: ()) - The string value to join. Convert other types explicitly (e.g. with strings.string(x)).
  • sep

    (str, default: "") - Separator string to use between values. Must be a literal Python string. Default: empty string.
  • index

    (Value | list[Value] | tuple[Value, ] | None, default: None) - Ordering key, or list of ordering keys, sorted ascending. Keys must be String, numeric, Date, or DateTime; entity- and hash-valued keys are rejected, so use a portable scalar identity such as an id property. Omit to order by the joined value.

Returns

  • Aggregate - An Aggregate representing the computation of the joined string. Returns String.

Examples

Join distinct employee names alphabetically with comma separator:

select(aggregates.string_join(Employee.name, sep=", "))

Join event labels in time order, keeping repeats via a unique id:

select(aggregates.string_join(Event.label, sep=", ", index=[Event.timestamp, Event.id]))

Join product tags per category:

select(
Category,
aggregates.string_join(Product.tag, sep="; ")
.per(Category)
.where(Product.category == Category),
)