[odb-users] "INSERT OR UPDATE" or equivalent

Boris Kolpackov boris at codesynthesis.com
Fri Jan 31 08:00:55 EST 2020

Adnan RIHAN <axel50397 at gmail.com> writes:

> 2) Try to load() an object by id, update() it accordigly or catch
>    odb::object_not_persistent them persist().

I would use find() instead of load() to avoid the exception.

> It would be great if it was possible to save an object using
> "INSERT OR UPDATE", or "ON DUPLICATE KEY" under the hood.

Yes, this could be a useful feature (commonly referred to as
"UPSERT"). However, I don't believe all the databases/versions
that we support have it. Also, the semantics can get nuanced,
especially if we try to emulate it for databases that don't
have the native support. You can see this page for some gory


More information about the odb-users mailing list