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

INSERT ... ON DUPLICATE KEY UPDATE #271

Open
1 of 3 tasks
deividaspetraitis opened this issue May 10, 2021 · 3 comments
Open
1 of 3 tasks

INSERT ... ON DUPLICATE KEY UPDATE #271

deividaspetraitis opened this issue May 10, 2021 · 3 comments
Assignees

Comments

@deividaspetraitis
Copy link

Is your feature request related to a problem? Please describe.

I might missed some details in docs but was not able to figure out how to construct INSERT ... ON DUPLICATE KEY UPDATE statement instead of INSERT IGNORE ... ON DUPLICATE KEY UPDATE

For example given example in docs:

        db := goqu.Dialect("mysql")
	insertSQL, args, _ := db.Insert("items").
		Rows(
			goqu.Record{"name": "Test1", "address": "111 Test Addr"},
			goqu.Record{"name": "Test2", "address": "112 Test Addr"},
		).
		OnConflict(goqu.DoUpdate("key", goqu.Record{"updated": goqu.L("NOW()")})).
		ToSQL()
	fmt.Println(insertSQL, args)

Would produce:

INSERT IGNORE INTO `items` (`address`, `name`) VALUES ('111 Test Addr', 'Test1'), ('112 Test Addr', 'Test2') ON DUPLICATE KEY UPDATE `updated`=NOW() []

I am looking for a way to construct:

INSERT INTO `items` (`address`, `name`) VALUES ('111 Test Addr', 'Test1'), ('112 Test Addr', 'Test2') ON DUPLICATE KEY UPDATE `updated`=NOW() []

Describe the solution you'd like

I think an option allowing to choose between INSERT and INSERT IGNORE while constructing statement would solve this problem, for example:

        db := goqu.Dialect("mysql")
	insertSQL, args, _ := db.Insert("items").Ignore(false).
        ...

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Dialect

  • postgres
  • mysql
  • sqlite3
@kirill-lokhmatov
Copy link

kirill-lokhmatov commented Dec 19, 2022

yes it looks like a bug.

if isg.DialectOptions().SupportsInsertIgnoreSyntax && o != nil {

here ignore is always produced on any conflict. Created a PR #373

@jwendel
Copy link

jwendel commented Apr 27, 2024

Just wondering, any update on this PR going in? I just stumbled on this as well.

I'm happy to attempt moving this PR to v9 if @doug-martin thinks PR #373 was an OK approach.

@autowp
Copy link

autowp commented Nov 4, 2024

Is any updates or workaround with that issue?

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

5 participants