Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

psql: Fix UPSERT query to respect conflict_target #1290

Merged
merged 1 commit into from
Jul 15, 2023

Conversation

agis
Copy link
Contributor

@agis agis commented Jul 14, 2023

The Postgres driver, for the following method call:

record.Upsert(ctx, db, false, []string{"foo"}, boil.None(), boil.Infer())

...would omit the conflict_target parameter[1], i.e. foo, from the query:

INSERT INTO "cars" ("id", "foo") VALUES ($1,$2) ON CONFLICT DO NOTHING

This patch changes the behavior so that the conflict_target is respected, resulting in the following:

INSERT INTO "cars" ("id", "foo") VALUES ($1,$2) ON CONFLICT ("foo") DO NOTHING

Fixes #1289

[1] https://www.postgresql.org/docs/15/sql-insert.html#SQL-ON-CONFLICT

The Postgres driver, for the following method call:

    record.Upsert(ctx, db, false, []string{"foo"}, boil.None(), boil.Infer())

...would omit the conflict_target parameter[1], i.e. `foo`, from the
query:

    INSERT INTO "cars" ("id", "foo") VALUES ($1,$2) ON CONFLICT DO NOTHING

This patch changes the behavior so that the conflict_target is
respected, resulting in the following:

    INSERT INTO "cars" ("id", "foo") VALUES ($1,$2) ON CONFLICT ("foo") DO NOTHING

Fixes volatiletech#1289

[1] https://www.postgresql.org/docs/15/sql-insert.html#SQL-ON-CONFLICT
@agis agis force-pushed the psql-upsert-conflict_target branch from b926f17 to a0ded2f Compare July 14, 2023 07:06
@stephenafamo stephenafamo merged commit 2cf24c0 into volatiletech:master Jul 15, 2023
atzedus pushed a commit to atzedus/sqlboiler that referenced this pull request Oct 16, 2023
stephenafamo added a commit that referenced this pull request Oct 17, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

psql: Upsert ignores conflict_target query parameter
2 participants