drivers/pgsql:pgsql returning id should use quotation marks,when primary key is capital (#3638)

This commit is contained in:
Insua 2024-06-12 21:22:39 +08:00 committed by GitHub
parent 753965b9a9
commit d5825ab51c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,7 @@ package pgsql
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/gogf/gf/v2/database/gdb"
@ -55,7 +56,7 @@ func (d *Driver) DoExec(ctx context.Context, link gdb.Link, sql string, args ...
// check if it is an insert operation.
if !isUseCoreDoExec && pkField.Name != "" && strings.Contains(sql, "INSERT INTO") {
primaryKey = pkField.Name
sql += " RETURNING " + primaryKey
sql += fmt.Sprintf(` RETURNING "%s"`, primaryKey)
} else {
// use default DoExec
return d.Core.DoExec(ctx, link, sql, args...)