ON CONFLICT DO UPDATE requires inference specification or constraint name
- [x] The issue is present in the latest release.
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
I think this is related to the ID field, it generates with two indexes:

one named pkey and the other named id_key
Code that fails: https://github.com/Southclaws/storyden/blob/main/api/src/resources/category/db.go#L24-L45
Schema: https://github.com/Southclaws/storyden/blob/main/api/src/infra/db/schema/category.go
I followed the docs here for custom ID types: https://entgo.io/docs/schema-fields#id-field and I'm probably going to switch from UUID to something like CUID in future so I want this to work without using the auto increment IDs.
Expected Behavior 🤔
Updates/upserts to work fine with one single unique ID constraint.
Also, if there are multiple constraints, how would that be done?
Steps to Reproduce 🕹
Grab the Storyden code above and run the test for TestCreatePost which initially seeds the database with users and categories, the seed data for categories is what fails.
Your Environment 🌎
| Tech | Version |
|---|---|
| Go | 1.18 |
| Ent | 0.10.1 |
| Database | Postgres |
| Driver | github.com/jackc/pgx/v4/stdlib |
@Southclaws I think this is Postgres specific.
It works when you specify the conflict target columns using .OnConflictColumns(...)
I got stuck on the same error and found a document about upsert in PostgreSQL.
https://entgo.io/docs/crud/#upsert-one
imo, this is a bug in postgresql.
- user should be able to specify an action "on any conflict" ... if another conflict occurs... throw an error
- user should be able to specify multiple on-conflict clauses one for each conflict type
neither of those are available, leaving postgres on-conflict-do-nothing the only way to go!