Rick Smith
Rick Smith

Reputation: 9251

How do I update column's values from another column?

In short, I'm trying to do the following using the gorm package.

UPDATE TableName t SET t.col1 = t.col2;

Is there a way to do where gorm only does 1 query?

Upvotes: 1

Views: 1146

Answers (1)

jchavannes
jchavannes

Reputation: 2720

You can do this using Gorm methods

db.Table("TableName t").Update("t.col1", gorm.Expr("t.col2"))

Source: https://github.com/jinzhu/gorm/issues/1947#issuecomment-397376537

Upvotes: 2

Related Questions