I have a record I am trying to upsert using Bob however it needs to be conditional but it doesn’t appear that the Upsert
method on Table
supports this. Is there a way that I can implement this?
setter := &Entity{
ID: 1,
counter: 3
}
upsertResult, err := SomeTable.Upsert(
ctx,
exec,
true,
[]string{"ID"},
[]string{"counter"},
setter
}
This works as expected however I am trying to ensure counter can only increase, this would roughly translate to the query:
INSERT INTO count (ID, counter)
VALUES ($1, $2)
ON CONFLICT (ID) DO UPDATE SET
counter = CASE
WHEN EXCLUDED.counter > count.counter THEN EXCLUDED.counter
ELSE count.counter
END;
any help would be greatly appreciated