go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
89 stars 678 forks source link

Incorrect ON CONFLICT when using composite primary key #652

Open johannes-riecken opened 11 months ago

johannes-riecken commented 11 months ago

Explain your user case and expected results

I'm using a composite primary key for a table that references a list of entities in another table.

The error I get is

2023/10/02 15:24:09 testing postgres...

2023/10/02 15:24:10 gorm-playground/main_test.go:13 ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
[0.952ms] [rows:0] INSERT INTO "tags" ("pet_first_name","pet_last_name","name") VALUES ('Hasso','McDog','foo') ON CONFLICT DO UPDATE SET "pet_first_name"="excluded"."pet_first_name","pet_last_name"="excluded"."pet_last_name"

2023/10/02 15:24:10 gorm-playground/main_test.go:13 ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
[3.761ms] [rows:1] INSERT INTO "pets" ("first_name","last_name") VALUES ('Hasso','McDog')
--- FAIL: TestGORM (0.00s)
    main_test.go:14: ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
FAIL
FAIL    gorm.io/playground  0.238s