Upsert Queries¶
Rayforce-Py allows you to execute upsert queries in multiple ways.
Upsert is different than insert Insert. It uses match_by_first keyword argument
match_by_first : int
The number of first columns that Rayforce will search to find a match for updating. If no match is found, an insert is performed.
Upserting a single record¶
Using args:
The order of arguments must match the order of the table columns.
Using kwargs:
Upserting multiple records¶
Using args:
>>> table.upsert(
[1, 2, 3],
["Alice", "Bob", "Sam"],
[28.5, 15.3, 10.2],
match_by_first=1,
).execute()
The order of arguments must match the order of the table columns.
Using kwargs:
>>> table.upsert(
id=[1, 2, 3],
name=["Alice", "Bob", "Sam"],
age=[28.5, 15.3, 10.2],
match_by_first=1
).execute()
Inplace vs By Reference Operations
The upsert() operation can work with both in-memory tables (inplace) and saved tables (by reference).
Learn more about the difference between Inplace and by reference operations.