go-zero
go-zero copied to clipboard
bulkinsert does not support doaller placeholders
What category of issue (goctl or sdk)?
sdk
the source code in core/stores/sqlx/bulkinserter.go
func parseInsertStmt(stmt string) (bulkStmt, error) {
...
var variables int
var valueFormat string
var suffix string
left := strings.IndexByte(lower[pos:], '(')
if left > 0 {
right = strings.IndexByte(lower[pos+left:], ')')
if right > 0 {
values := lower[pos+left : pos+left+right]
for _, x := range values {
if x == '?' {
variables++
}
}
valueFormat = stmt[pos+left : pos+left+right+1]
suffix = strings.TrimSpace(stmt[pos+left+right+1:])
}
}
if variables == 0 {
return emptyBulkStmt, fmt.Errorf("no variables: %q", stmt)
}
....
}
What type of issue (feature|bug|suggestion)?
Maybe a bug. I am not sure
When calculating variables in parseInsertStmt, only the mysql placeholder ? is judged, and the postgresql placeholder $ is not judged, resulting in
no variables: \"insert into \\\"org\\\".\\\"role_user\\\" (created_at,updated_at,role_id,user_id) values ($1, $2, $3, $4)\"
What version of Goctl are you using (goctl --version)?
$ goctl --version 1.4.4
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using ?
ARCH = "arm64" GOCTL_VERSION = "1.4.4" GO_VERSION = "go1.20.2" OS = "darwin"
What did you do?
demo but need redis
What did you expect to see?
What did you see instead?
Verified in v1.5.3?
Verified in v1.5.3?
Yes. error still exists。
no variables: \"insert into \\\"org\\\".\\\"role_user\\\" (created_at,updated_at,role_id,user_id) values ($1, $2, $3, $4)\"
Just use ? instead of $x.
Just use
?instead of$x.
You mean postgresql also use ? as placeholder in bulk insert?
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.