REPLACE (Upsert)
Insert rows, replacing existing rows on primary key conflict.
SereneDB provides two mechanisms for upsert behavior:
ON CONFLICT
Conflict policy
Alternatively, set the session-level conflict policy to apply to all INSERT statements:
Parameters
| Parameter | Description |
|---|---|
ON CONFLICT DO NOTHING | Silently skip rows that conflict with an existing primary key |
ON CONFLICT DO UPDATE SET | Update the existing row with new values on conflict |
sdb_write_conflict_policy | Session-level default: emit_error (default), do_nothing, or replace |
Examples
ON CONFLICT DO NOTHING
INSERT INTO products (id, name, price)
VALUES (1, 'Widget', 9.99), (2, 'Gadget', 19.99)
ON CONFLICT DO NOTHING;
Session-level replace policy
SET sdb_write_conflict_policy = replace;
INSERT INTO products (id, name, price)
VALUES (1, 'Widget Pro', 14.99), (3, 'Gizmo', 29.99);
-- Row id=1 is replaced, row id=3 is inserted
Reset to default:
SET sdb_write_conflict_policy = emit_error;