go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

bulkinsert does not support doaller placeholders

Open fiecato opened this issue 2 years ago • 5 comments
trafficstars

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?

fiecato avatar Jul 04 '23 09:07 fiecato

Verified in v1.5.3?

kevwan avatar Jul 07 '23 03:07 kevwan

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)\"

fiecato avatar Jul 14 '23 02:07 fiecato

Just use ? instead of $x.

kevwan avatar Jul 21 '23 15:07 kevwan

Just use ? instead of $x.

You mean postgresql also use ? as placeholder in bulk insert?

fiecato avatar Jul 24 '23 09:07 fiecato

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 25 '24 01:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Oct 26 '24 02:10 github-actions[bot]