squirrel
squirrel copied to clipboard
Upsert/On Conflict support
As a follow-up to the previous issue #83, I would like to know how to handle the suffix approach for updating a conflict when there is a multi-row insert statement.
this is a dated issue, but I thought this was pretty trivial.
//use Squirrel query builder due to limitation of jet
query := sq.Insert("funcap.ht_fleet_status").
Columns("router_name", "uptime_value", "last_modified")
for router, duration := range routers {
query = query.Values(router, sq.Expr("?::interval", duration), "now()")
}
query = query.Suffix("on conflict(router_name) do update set uptime_value = excluded.uptime_value, last_modified = now()")
it's the same pattern if you have multiple values or a single values caluse.