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: Upsert ignores conflict_target query parameter #1289

Closed
agis opened this issue Jul 13, 2023 · 4 comments · Fixed by #1290
Closed

psql: Upsert ignores conflict_target query parameter #1289

agis opened this issue Jul 13, 2023 · 4 comments · Fixed by #1290
Labels

Comments

@agis
Copy link
Contributor

agis commented Jul 13, 2023

What version of SQLBoiler are you using (sqlboiler --version)?

4.11.0

What is your database and version (eg. Postgresql 10)

Postgres 13

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

N/A

If this happened at runtime what code produced the issue? (if not applicable leave blank)

N/A

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

N/A

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

   Column   |            Type             | Collation | Nullable | Default 
------------+-----------------------------+-----------+----------+---------
 id         | character varying           | C         | not null | 
 foo        | character varying(255)      |           | not null | 
 brand      | boolean                     |           | not null | 
 created_at | timestamp without time zone |           | not null | now()
 updated_at | timestamp without time zone |           | not null | now()
Indexes:
    "cars_pkey" PRIMARY KEY, btree (id)
    "idx_foo" UNIQUE, btree (foo)

Further information. What did you do, what did you expect?

The following call:

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

results in the following unexpected query:

INSERT INTO "cars" ("id", "foo", "brand", "created_at", "updated_at") VALUES ($1,$2,$3,$4,$5) ON CONFLICT DO NOTHING

whereas I would expect it to result to the following:

INSERT INTO "cars" ("id", "foo", "brand", "created_at", "updated_at") VALUES ($1,$2,$3,$4,$5) ON CONFLICT ("foo") DO NOTHING

I've a draft PR ready if this is indeed a bug and not something I'm misunderstanding.

@stephenafamo
Copy link
Collaborator

This looks like a bug, the PR would be much appreciated 🙏🏾

agis added a commit to agis/sqlboiler that referenced this issue 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 volatiletech#1289

[1] https://www.postgresql.org/docs/15/sql-insert.html#SQL-ON-CONFLICT
agis added a commit to agis/sqlboiler that referenced this issue 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 volatiletech#1289

[1] https://www.postgresql.org/docs/15/sql-insert.html#SQL-ON-CONFLICT
@agis
Copy link
Contributor Author

agis commented Jul 17, 2023

@stephenafamo can we please backport this to v4, since it seems to me like a trivial bugfix?

@stephenafamo
Copy link
Collaborator

I just need to cut a new release soon. We're still on v4

@agis
Copy link
Contributor Author

agis commented Jul 18, 2023

Thanks a lot, that would be greatly appreciated!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants