-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project?Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of serviceand privacy statement.We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database/gdb: postgresql Composite primary key for non-ID primary key LastInsertId() support #3675
Comments
DescriptionScenes:
Example: _,err:=dao.Company.
OmitEmpty().
OnConflict(
dao.Company.Columns().Name,
dao.Company.Columns().ProjectId,
).
OnDuplicateEx(
dao.Company.Columns().Id,
dao.Company.Columns().Name,
dao.Company.Columns().ProjectId,
dao.Company.Columns().CreateTime,
).Save(companies) need:
question:
Temporary solution: As you can see from the following code, you can control the fields returned by the RETURNING statement by configuring the internalPrimaryKeyInCtx value in ctx
const(
internalPrimaryKeyInCtxgctx.StrKey="primary_key"
)
// Check if it is an insert operation with primary key.
ifvalue:=ctx.Value(internalPrimaryKeyInCtx);value!=nil{
varOKbool
pkField,ok=value.(gdb.TableField)
if!ok{
isUseCoreDoExec=true
}
}else{
isUseCoreDoExec=true
}
// check if it is an insert operation.
if!isUseCoreDoExec&&pkField.Name!=""&&strings.Contains(sql,"INSERT INTO") {
primaryKey=pkField.Name
sql+=fmt.Sprintf(` RETURNING "%s" `,primaryKey)
}else{
// use default DoExec
returnd.Core.DoExec(ctx,link,sql,args...)
} The following code shows that the LastInsertId() operation requires RETURNING that the fields in xxx need to be of type int
Therefore, after changing the code to the following, LastInsertId() can be called normally:
Summarize:
AdditionalNo response |
Description
Cảnh tượng:
Example:
Nhu cầu:
Vấn đề:
INSERT INTO... RETURNING "name"
,Ở chấp hành LastInsertId() khi đem phản hồiLastInsertId is not supported by primary key type
Sai lầmLâm thời giải quyết phương án:
Từ như sau số hiệu trung có thể nhìn đến, có thể thông qua ở ctx trung phối trí internalPrimaryKeyInCtx giá trị tới khống chế RETURNING câu nói phản hồi tự đoạn
Như sau số hiệu triển lãm LastInsertId() thao tác yêu cầu RETURNING xxx trung tự đoạn yêu cầu vì int loại hình
Bởi vậy sửa chữa vì như sau số hiệu sau nhưng bình thường thuyên chuyển LastInsertId():
Tổng kết:
Additional
No response
The text was updated successfully, but these errors were encountered: