squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

Upsert/On Conflict support

Open aryannr97 opened this issue 2 years ago • 1 comments

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.

aryannr97 avatar Dec 25 '23 14:12 aryannr97

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.

safaci2000 avatar Sep 25 '24 19:09 safaci2000