DB_Table.update_rows
Group: Output
Documentation
Updates the database table with the contents of the provided table. This operation will only work if this table is a 'trivial' table reference, like returned by Connection.query, so it corresponds directly to a table existing in a Database. If the target table is transformed in any way, this correspondence is lost and the update operation cannot be performed on such a transformed object.
Arguments
source_table: the table containing values for the update. This table may be in-memory (in which case it will be uploaded as a temporary table) or any database query with any desired transformations applied, as long as it is coming from the same Connection as the target table.update_action: specifies the update strategy - how to handle existing new and missing rows.key_columns: the names of the columns to use identify correlate rows from the source table with rows in the target table. This key is used to determine if a row from the source table exists in the target or is a new one.error_on_missing_columns: if set toFalse(the default), any columns missing from the source table will be left unchanged or initialized with the default value if inserting. If a missing column has no default value, this will trigger aSQL_Error. If set toTrue, any columns missing from the source will cause an error. - on_problems: the behavior to use when encountering non-fatal problems.
Errors
- If
key_columnsare not present in either the source or target tables, aMissing_Input_Columnserror is raised. - If the target table does not exist, a
Table_Not_Founderror is raised. - If
error_on_missing_columnsis set toTrueand a column is missing from the source table, aMissing_Input_Columnserror is raised. - If the source table contains columns that are not present in the target
table, an
Unmatched_Columnserror is raised. - If a column in the source table has a type that cannot be trivially
widened to the corresponding column in the target table, a
Column_Type_Mismatcherror is raised. If the types do not match but can be widened, anInexact_Type_Coercionis reported. - If
update_actionisInsertand a row with the same key already exists in the target table, aRows_Already_Presenterror is raised. - If the
update_actionisUpdateand some rows in the source have no corresponding rows in the target table, aUnmatched_Rowserror is raised. - If the source table contains multiple rows for the same key, a
Non_Unique_Keyerror is raised. - If a row in the source table matches multiple rows in the target table, a
Multiple_Target_Rows_Matched_For_Updateerror is raised. - If another database error occurs, an
SQL_Erroris raised.
If any error was raised, the data in the target table is not modified.
Remarks
Type Widening
Smaller types can be widened to a larger type, for example 32-bit integer column can be widened to a 64-bit integer column, but not vice versa (because larger numbers could not fit the smaller type and the type of the column in the target table cannot be changed).
Dry Run if Output disabled
If performing output actions is disabled, only a dry run is performed and
no permanent changes occur. The operation checks for errors like missing
columns or mismatched types and if successful, returns the target table
unchanged with a Dry_Run_Operation warning attached.
More expensive checks, like clashing keys or unmatched rows are checked only on a sample of rows, so errors may still occur when the output action is enabled.