Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk insert assumed that the placeholders will always be at the end #694

Open
MichaelBui opened this issue Jan 29, 2021 · 8 comments
Open

Comments

@MichaelBui
Copy link

MichaelBui commented Jan 29, 2021

Current regex only accept placeholders at the end of the query:

var valueBracketReg = regexp.MustCompile(`\([^(]*.[^(]\)$`)

This doesn't work with INSERT .... ON DUPLICATE KEY UPDATE....

@kazz187
Copy link

kazz187 commented Feb 2, 2021

same
#657

@aarengee
Copy link

aarengee commented Mar 9, 2021

Solved :
Problem : #667 (comment)

Solution : #667 (comment)

@powerman
Copy link

This is a regression since 18 Nov 2020 b63be72. Actually this issue is tracked in a lot of places: #505 (comment), #612 (comment), #690, #712, #705, #667 (comment), #657...

@jmoiron
Copy link
Owner

jmoiron commented Apr 8, 2021

This should work after #718 / v1.3.2, please reopen if you are still having issues.

@jmoiron jmoiron closed this as completed Apr 8, 2021
@Al2Klimov
Copy link

Wanted to manifest this issue's fix by https://github.com/Al2Klimov/sqlx/commit/a3897d3439c167a9e6f7b3cafb8e8e51d831dd36, but the tests fail:

➜  sqlx git:(feature/mysql-upsert) go test -race ./...
Disabling PG tests:
    dial tcp [::1]:5432: connect: connection refused
Disabling MySQL tests:
    invalid DSN: missing the slash separating the database name--- FAIL: TestFixBounds (0.00s)
    --- FAIL: TestFixBounds/named_syntax_w/_upsert (0.00s)
        named_test.go:375: mismatched results
    --- FAIL: TestFixBounds/mysql_syntax_w/_upsert (0.00s)
        named_test.go:375: mismatched results
FAIL
FAIL	github.com/jmoiron/sqlx	0.474s
ok  	github.com/jmoiron/sqlx/reflectx	(cached)
ok  	github.com/jmoiron/sqlx/types	(cached)
FAIL
➜  sqlx git:(feature/mysql-upsert)

@jmoiron TL;DR: it's still not fixed, but I seem not to have the permission to re-open this one.

CC @lippserd

@abraithwaite
Copy link
Contributor

Interesting. I noticed you changed the regex slightly, but not in a way which would cause issues for those tests.

Looking more closely, it appears that MySQL overloads the VALUES keyword for ON DUPLICATE KEY clauses.

A workaround would be to use the new. syntax for MySQL, if you're using a recent version of MySQL.

https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

@Al2Klimov
Copy link

if you're using a recent version of MySQL

That’s exactly the point! We – @Icinga – can’t enforce our customers' MySQL versions as they usually stick to their Distro's package sources.

@SenselessA
Copy link

SenselessA commented Jul 12, 2023

Still not fixed, I have same problem with 1.3.3 version sqlx

my example:
movies *[]models.Movie

_, err := tx.NamedExec(" INSERT INTO movies (id, kinopoisk_id) VALUES (:id, :kinopoisk_id) ON CONFLICT (id) DO UPDATE SET (id, kinopoisk_id) = (:id, :kinopoisk_id); ", movies)

lippserd pushed a commit to Icinga/icinga-go-library that referenced this issue Oct 10, 2023
lippserd pushed a commit to Icinga/icinga-go-library that referenced this issue Apr 26, 2024
lippserd pushed a commit to Icinga/icinga-go-library that referenced this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants