I can run an upsert in gorm using the following syntax:
result := db.orm.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&row)
however I only want to run the upsert if the data has changed - this ensures my updated_at timestamp is only modified if the data is different. Using SQL I can have the following query:
INSERT INTO X (
A,
B,
C
) VALUES (
$1, $2, $3
) ON CONFLICT (A) DO UPDATE SET
B = $2,
C = $3,
UpdatedAt = NOW()
WHERE (X.A, X.B, X.C) IS DISTINCT FROM ($1, $2, $3);
Is it possible to add this where clause using gorm?