upsert_#

swordfish.function.upsert_()#

Insert rows into a keyed table or indexed table if the values of the primary key do not already exist, or update them if they do.

Note

  • When using this function, please make sure the corresponding columns in table newData and obj are arranged in the same order, or the system may generate the wrong result or throw an error.

  • If obj is a DFS table with duplicated “keys” (as specified by keyColNames), upsert_ on rows with duplicated keys only updates the first row.

  • The behavior of this function is controlled by the enableNullSafeJoin configuration:

  • When enableNullSafeJoin=true, joining on null values is allowed, and upsert_ may update records that contain nulls.

  • When enableNullSafeJoin=false, joining on null values is not allowed, and upsert_ will not update records with nulls.

Parameters:
  • obj (Constant) – A keyed table, indexed table, or a DFS table.

  • newData (Constant) – An in-memory table.

  • ignoreNull (Constant, optional) – A oolean value, by default DFLT. If set to true, for the null values in newData, the corresponding elements in obj are not updated. The default value is false.

  • keyColNames (Constant, optional) – A STRING scalar/vector. When obj is a DFS table, keyColNames and the partitioning columns are considered as the key columns, by default DFLT.

  • sortColumns (Constant, optional) – A STRING scalar or vector, by default DFLT. The updated partitions will be sorted on sortColumns (only within each partition, not across partitions).