alias#
relationalai.std
#alias(ref: Producer, name: str) -> Var
Renames ref
so that it appears with the column name name
in query results.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
ref | Producer | The object to be aliased. |
name | str | The name to use as the alias. |
Returns#
A Var
object.
Example#
#import relationalai as rai
from relationalai.std import alias
model = rai.Model("people")
Person = model.Type("Person")
with model.rule():
Person.add(name="Joe")
with model.query() as select:
person = Person()
response = select(person.name)
print(response.results)
# Output:
# name <-- Column name is the property name
# 0 Alex
# You can change the default column name with `.alias()`.
with model.query() as select:
person = Person()
response = select(alias(person.name, "my_col"))
print(response.results)
# Output:
# my_col
# 0 Alex