diff --git a/tools/goctl/model/sql/builderx/builder.go b/tools/goctl/model/sql/builderx/builder.go index f579c0e3..bcf38015 100644 --- a/tools/goctl/model/sql/builderx/builder.go +++ b/tools/goctl/model/sql/builderx/builder.go @@ -125,7 +125,7 @@ func RawFieldNames(in interface{}, postgresSql ...bool) []string { func PostgreSqlJoin(elems []string) string { b := new(strings.Builder) for index, e := range elems { - b.WriteString(fmt.Sprintf("%s = $%d, ", e, index+1)) + b.WriteString(fmt.Sprintf("%s = $%d, ", e, index+2)) } if b.Len() == 0 { diff --git a/tools/goctl/model/sql/builderx/builder_test.go b/tools/goctl/model/sql/builderx/builder_test.go index 31bf7680..5f3f4614 100644 --- a/tools/goctl/model/sql/builderx/builder_test.go +++ b/tools/goctl/model/sql/builderx/builder_test.go @@ -121,5 +121,5 @@ func TestBuildSqlLike(t *testing.T) { func TestJoin(t *testing.T) { ret := PostgreSqlJoin([]string{"name", "age"}) - assert.Equal(t, "name = $1, age = $2", ret) + assert.Equal(t, "name = $2, age = $3", ret) } diff --git a/tools/goctl/model/sql/gen/update.go b/tools/goctl/model/sql/gen/update.go index 89248284..7887826a 100644 --- a/tools/goctl/model/sql/gen/update.go +++ b/tools/goctl/model/sql/gen/update.go @@ -33,7 +33,11 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error) keyVariableSet.AddStr(key.KeyLeft) } - expressionValues = append(expressionValues, "data."+table.PrimaryKey.Name.ToCamel()) + if postgreSql { + expressionValues = append([]string{"data." + table.PrimaryKey.Name.ToCamel()}, expressionValues...) + } else { + expressionValues = append(expressionValues, "data."+table.PrimaryKey.Name.ToCamel()) + } camelTableName := table.Name.ToCamel() text, err := util.LoadTemplate(category, updateTemplateFile, template.Update) if err != nil {