Skip to main content

Upsert support in Spanner targets

Consider two common problems when writing to Spanner:

  • When performing an insert, a record with the same primary key already exists.

  • When performing an update, no record matches the specified primary key.

"Upsert" is an alternative that deals with both those issues at once. If a record with the specified primary key exists, it updates the record; otherwise, it performs an insert. Upserts are enabled by two properties:

  • When Execute Insert As Update is True, all INSERT operations will be converted to INSERT_OR_UPDATE. When an insert is not possible because an existing record has the specified primary key, the existing record will be updated.

  • When Execute Update As Insert is True, all UPDATE operations will be converted to INSERT_OR_UPDATE. When an update is not possible because no record with the specified primary key exists, a new record will be created.