diff --git a/orm/db.go b/orm/db.go index 6b749425..87d08df6 100644 --- a/orm/db.go +++ b/orm/db.go @@ -536,6 +536,8 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a updates := make([]string, len(names)) var conflitValue interface{} for i, v := range names { + // identifier in database may not be case-sensitive, so quote it + v = fmt.Sprintf("%s%s%s", Q, v, Q) marks[i] = "?" valueStr := argsMap[strings.ToLower(v)] if v == args0 { diff --git a/orm/models_test.go b/orm/models_test.go index d6c2b581..d60be27a 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -477,9 +477,7 @@ go test -v github.com/astaxie/beego/orm #### TiDB export ORM_DRIVER=tidb export ORM_SOURCE='memory://test/test' -go test -v github.com/astaxie/beego/orm - -`) +go test -v github.com/astaxie/beego/orm`) os.Exit(2) } diff --git a/orm/orm_test.go b/orm/orm_test.go index f1f2d85e..ce6fc6d4 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -2297,6 +2297,11 @@ func TestInsertOrUpdate(t *testing.T) { throwFailNow(t, AssertIs(user2.Status, test.Status)) throwFailNow(t, AssertIs(user2.Password, strings.TrimSpace(test.Password))) } + + //postgres ON CONFLICT DO UPDATE SET can`t use colu=colu+values + if IsPostgres { + return + } //test3 + _, err = dORM.InsertOrUpdate(&user2, "user_name", "status=status+1") if err != nil {