Lookup
Relational functions lookup
syntax
- lookup(relation, values)
- values[relation]
- relation -> values
definition
lookup(relation,values) or values[relation] or relation -> values results in a Data item with the values of the Argument values for the Domain unit of the relation Attribute.
The relation argument defines which values are looked up in the domain unit of the values attribute.
The resulting data item has the same Values unit as the values argument and the same domain unit as the relation argument.
applies to
- relation: Data item with the Index numbers of the domain unit of the values attribute.
- values: attribute with the requested values to be looked up.
description
The relation towards the domain unit of argument values can be derived from any foreign key attribute with the Rlookup function.
The Rjoin function can be used to relate on foreign key attributes, without the explicit use of index numbers.
value info
Both ways a resulting value can be null are visible in the [[value info]] dialog without further explanation, because it resolves the explained row into relation and then follows that value into values. In the example below, row 2 shows Region_rel = 2 and Region/Temp at row 2 = null, while row 5 shows Region_rel = null and stops there. A relation value outside the Domain unit of values is shown as <OutOfRange>.
performance
O(n) where n = number of elements in the domain of relation. Direct array indexing for each element.
example
attribute<degrees> LTemp (City) := lookup(City/Region_rel, Region/Temp);
attribute<degrees> LTemp (City) := Region/Temp[City/Region_rel];
attribute<degrees> LTemp (City) := City/Region_rel -> Region/Temp;
| City/Region_rel | LTemp |
|---|---|
| 0 | 12 |
| 1 | 11 |
| 2 | null |
| 1 | 11 |
| 3 | 14 |
| null | null |
| 3 | 14 |
domain City, nr of rows = 7
| Region/Temp |
|---|
| 12 |
| 11 |
| null |
| 14 |
| 13 |
domain Region, nr of rows = 5