DB_Table.merge
mergelookup_tablekey_columnsadd_new_columnsallow_unmatched_rowson_problems
Group: Calculations
Aliases: lookup
Documentation
Merges this table with a lookup table. New values are looked up in the lookup table based on the key_columns
. Columns that exist in the lookup table where a match was found are replaced by values from the lookup table. Columns not found are left unchanged. This operation is similar to Table.update_rows
, but just returns a new Table
instance, instead of updating the table in-place (which is only possible for Database tables).
Arguments
lookup_table
: The table to use for looking up values.key_columns
: Specifies the columns to use for correlating rows between the two tables. Must identify values uniquely withinlookup_table
.add_new_columns
: Specifies if new columns from the lookup table should be added to the result. IfFalse
, anUnexpected_Extra_Columns
problem is reported.allow_unmatched_rows
: Specifies how to handle missing rows in the lookup. IfFalse
(the default), anUnmatched_Rows_In_Lookup
error is raised. IfTrue
, the unmatched rows are left unchanged. Any new columns will be filled withNothing
.on_problems
: Specifies how to handle problems if they occur, reporting them as warnings by default.
Errors
- If this table or the lookup table is lacking any of the columns
specified in
key_columns
, aMissing_Input_Columns
error is raised. - If an empty vector is provided for
key_columns
, aNo_Input_Columns_Selected
error is raised. - If a single row is matched by multiple entries in the lookup table,
a
Non_Unique_Key
error is raised. - If a column that is being updated from the lookup table has a type
that is not compatible with the type of the corresponding column in
this table, a
No_Common_Type
error is raised. - If a key column contains
Nothing
values in the lookup table, aNull_Values_In_Key_Columns
error is raised. - If
allow_unmatched_rows
isFalse
and there are rows in this table that do not have a matching row in the lookup table, anUnmatched_Rows_In_Lookup
error is raised. - The following problems may be reported according to the
on_problems
setting:- If any of the
key_columns
is a floating-point type, aFloating_Point_Equality
. - If
add_new_columns
isFalse
and the lookup table has columns that are not present in this table, anUnexpected_Extra_Columns
.
- If any of the
Remarks
Result Ordering
When operating in-memory, this operation preserves the order of rows
from this table (unlike join
).
In the Database backend, there are no guarantees related to ordering of
results.